JavaScript ARRAYS of OBJECTS are easy! 🍎

11 months ago
3

00:00:00 array of objects
00:01:29 access object properties
00:02:19 push()
00:02:59 pop()
00:03:11 splice()
00:03:28 forEach()
00:04:08 map()
00:05:18 filter()
00:07:09 reduce()

const fruits = [ {name: "apple", color: "red", calories: 95},
{name: "orange", color: "orange", calories: 45},
{name: "banana", color: "yellow", calories: 105},
{name: "coconut", color: "white", calories: 159},
{name: "pineapple", color: "yellow", calories: 37}];

// Access properties of a fruit object
console.log(fruits[0].calories);

// Add a new fruit object
fruits.push({ name: "grapes", color: "purple", calories: 62});

// Remove the last fruit object
fruits.pop();

// Remove fruit objects by indices
fruits.splice(1, 2);

Loading comments...