Add a property to every object of an array - Array.forEach

PHOTO EMBED

Tue Jun 29 2021 11:45:43 GMT+0000 (Coordinated Universal Time)

Saved by @hisam #object #array #javascript #vanilla

cars.forEach(car => {
 car['size'] = "large";
 if (car.capacity <= 5){
   car['size'] = "medium";
 }
 if (car.capacity <= 3){
   car['size'] = "small";
 }
});
content_copyCOPY