Sort an array by a property - Array.sort

PHOTO EMBED

Tue Jun 29 2021 11:46:09 GMT+0000 (UTC)

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