JavaScript ARRAYS of OBJECTS are easy! 🍎

Поділитися
Вставка
  • Опубліковано 31 січ 2025

КОМЕНТАРІ • 20

  • @BroCodez
    @BroCodez  Рік тому +10

    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);
    // ---------- forEach() ----------
    fruits.forEach(fruit => console.log(fruit));
    fruits.forEach(fruit => console.log(fruit.name));
    fruits.forEach(fruit => console.log(fruit.color));
    fruits.forEach(fruit => console.log(fruit.calories));
    // ---------- 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);

  • @KallMeMoh
    @KallMeMoh Рік тому +3

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

  • @joehaar1466
    @joehaar1466 Рік тому +4

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

  • @navnitkhandait6750
    @navnitkhandait6750 11 місяців тому

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

  • @jayboy6430
    @jayboy6430 6 місяців тому

    Best clarification by far. I've now subscribed.

  • @elawet435
    @elawet435 Рік тому +3

    You’re amazing dude, thank u ❤

  • @AviShpayer
    @AviShpayer 9 місяців тому

    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."

  • @Kaif-vp4zd
    @Kaif-vp4zd 27 днів тому

    absolutely amazing and easy to understand

  • @peterarcuri3291
    @peterarcuri3291 10 місяців тому +1

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

  • @piotrmazgaj
    @piotrmazgaj 5 місяців тому +1

    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.

    • @RakeshMahore-i5t
      @RakeshMahore-i5t 4 місяці тому

      hope you are trying to write the code in vs code at the end of every video

  • @hunin27
    @hunin27 Рік тому +1

    thanks bro

  • @AVATELIEN
    @AVATELIEN Рік тому +1

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

  • @peterarcuri3291
    @peterarcuri3291 10 місяців тому +3

    'grapges' 😂

  • @idontknowwhattonamethischa4592

    FRUITS

  • @friedricht3908
    @friedricht3908 Рік тому +1

    First

  • @abdeSaves
    @abdeSaves 9 місяців тому +2

    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.

    • @hamzagohar2048
      @hamzagohar2048 6 місяців тому

      yea it does feel like that probably because it is a recording not a live lecture where we can ask and clarify i usually get help if i feel stuck by using chatgpt

  • @ManuelRamos-l4h
    @ManuelRamos-l4h 7 місяців тому

    bro

  • @navnitkhandait6750
    @navnitkhandait6750 11 місяців тому +2

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