Decorators
Decorators
Decorators
let cars = [{"color": "purple","type": "minivan","registration": new Date('2017-01-03'),"capacity": 7},{"color": "red","type": "station wagon","registration": new Date('2018-03-03'),"capacity": 5},{...},...]
let car = {
"color": "red",
"type": "cabrio",
"registration": new Date('2016-05-02'),
"capacity": 2
}
cars.unshift(car);
let car = {
"color": "red",
"type": "cabrio",
"registration": new Date('2016-05-02'),
"capacity": 2
}
cars.push(car);
Array.splice( {index where to start}, {how many items to remove}, {items to add} );
let car = {
"color": "red",
"type": "cabrio",
"registration": new Date('2016-05-02'),
"capacity": 2
}
cars.splice(2, 0, car);
let car = cars.find(car => car.color === "red");
let car = cars.find(car => car.color === "red" && car.type === "cabrio");
let redCars = cars.filter(car => car.color === "red");
console.log(redCars);
cars.forEach(car => {
car['size'] = "large";
if (car.capacity <= 5){
car['size'] = "medium";
}
if (car.capacity <= 3){
car['size'] = "small";
}
});
let sortedCars = cars.sort((c1, c2) => (c1.capacity < c2.capacity) ? 1 :
(c1.capacity > c2.capacity) ? -1 : 0);
console.log(sortedCars);
Array.every and Array.some come handy when we just need to check each object for a specific condition.
cars.some(car => car.color === "red" && car.type === "cabrio");
// output: true
cars.every(car => car.capacity >= 4);
// output: false
Reference Link : click Here