5 Ways to Add Items to Arrays in JavaScript

แชร์
ฝัง
  • เผยแพร่เมื่อ 4 ม.ค. 2025

ความคิดเห็น • 10

  • @Uncaught_in_promise
    @Uncaught_in_promise ปีที่แล้ว +1

    Thank you for a fresh reminder

  • @fraidoonhu9284
    @fraidoonhu9284 ปีที่แล้ว +2

    Well a great refresher

  • @installgentoo4362
    @installgentoo4362 ปีที่แล้ว +1

    00:00 - array.push()
    1:25 - array.unshift()
    2:16 - array.splice()
    4:18 - array.concat()
    5:54 - spread syntax

  • @karlstenator
    @karlstenator ปีที่แล้ว

    Thanks Dom, solid vid as always.

  • @ban_droid
    @ban_droid ปีที่แล้ว +5

    The last method, you dont need to use spread operator again to insert it
    const moreDevices = [...devices, "Mobile Phone", "Tablet"];

  • @dimitrisqq
    @dimitrisqq ปีที่แล้ว

    Hey! Great refresher as the others say! Is one faster or preferred than another? I'm slowly trying to understand best-best practices, started learning about memory leaks etc, and it's a whole new world. WeakSets, WeakMaps, Proxies, etc (Of course, I have to thank you about Proxies, your video was the only one I was comfortable with)

  • @Cahnisama
    @Cahnisama ปีที่แล้ว

    Note that the last one creates a NEW array, it doesn't change the old one, you still have access to the old one.

  • @bmehder
    @bmehder ปีที่แล้ว +1

    Some of these array methods mutate the original array. Every time you mutate an array, a puppy dies. Please think of the puppies! Chrome has implemented some of the new array methods that are alternatives to splice, reverse, and sort. The new methods are called toReversed, toSpliced, and toSorted.

  • @Uncaught_in_promise
    @Uncaught_in_promise ปีที่แล้ว

    Johnny be good