JavaScript ARRAYS of OBJECTS are easy! 🍎

preview_player
Показать описание
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

// Add a new fruit object

// Remove the last fruit object

// Remove fruit objects by indices
Рекомендации по теме
Комментарии
Автор

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


// 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);

// forEach()
fruits.forEach(fruit => console.log(fruit));
fruits.forEach(fruit => console.log(fruit.name));
fruits.forEach(fruit => console.log(fruit.color));
fruits.forEach(fruit =>

// map()
const fruitNames = fruits.map(fruit => fruit.name);
const fruitColors = fruits.map(fruit => fruit.color);
const fruitCalories = fruits.map(fruit => fruit.calories);

console.log(fruitNames);
console.log(fruitColors);
console.log(fruitCalories);

// filter()
const yellowFruits = fruits.filter(fruit => fruit.color === "yellow");
const lowCalFruits = fruits.filter(fruit => fruit.calories < 100);
const highCalFruits = fruits.filter(fruit => fruit.calories >= 100);

console.log(yellowFruits);
console.log(lowCalFruits);
console.log(highCalFruits);

// reduce()
const maxFruit = fruits.reduce( (max, fruit) =>
fruit.calories > max.calories ?
fruit : max);

const minFruit = fruits.reduce( (min, fruit) =>
fruit.calories < min.calories ?
fruit : min);

console.log(maxFruit);
console.log(minFruit);

BroCodez
Автор

Thank you for the video. There was one thing in the video that I didn't understand and had to ask chatGPT about it.
When you name the parameter in the filters as "fruit" instead of "fruits" I didn't understand how did that work, I thought it should be fruits in plural. I even thought that maybe Javascript understands singular from plural.
Luckly, chatGPT explained it:
"Whether you name this parameter fruit or fruits or anything else doesn't affect how JavaScript processes the code. It's just a variable name."

AviShpayer
Автор

Best clarification by far. I've now subscribed.

jayboy
Автор

The best tutorials I could fine. Just wanna say thank you. Currently learning Python with your lessons.

joehaar
Автор

yo this channel is amazing, why is it heavily underrated wtf, keep going man!

klmoh
Автор

this man making it very easy to learn complex topics in very esy way

navnitkhandait
Автор

<*_> This is my seal. I have watched the entire video, understood it, and I can explain it in my own words, thus I have gained knowledge. This is my seal. <_*>

piotrmazgaj
Автор

Bro Code you're awesome!! Thank you for the wisdom!

peterarcuri
Автор

Hey brocode thanks for this do u have a long video about the same subject im still confused with those

=> :

Tiger__Man
Автор

Hey bro, no offense intended, but it seems like you always tend to spend more time elaborating on simple concepts while rushing through the more challenging aspects of what you're teaching. Just an observation.

Abde
Автор

this man making it very easy to learn complex topics in very esy way

navnitkhandait