I think it is just showing that there are three ways to make a mutative change to an array, each line does the same thing.
array.push('🐴') simply adds to the end of the array array.splice(array.length, 0, '🐴') removes 0 items from the end of the array, and adds one item array[array.length] = '🐴' adds an item to a specific position, which in this case is at the end of the array
Something for beginners (I'm pretty sure you already knew about this):
One hacky way to add an empty item to an array (if we can even call it appending an item to an array, I think more appropriate term would be resizing) would be:
An experienced software developer with a strong background in developing award-winning web and mobile applications for diverse clients with 6+ years of industry experience.
The point about not mutating if you need the array elsewhere is a good one, especially for parallel or concurrent programming. Even in single threaded JavaScript you might have passed an array by reference and so mutate things unexpectedly. Generally I find non-mutation to be a more relaxing method!
I think it is just showing that there are three ways to make a mutative change to an array, each line does the same thing.
array.push('🐴')simply adds to the end of the arrayarray.splice(array.length, 0, '🐴')removes 0 items from the end of the array, and adds one itemarray[array.length] = '🐴'adds an item to a specific position, which in this case is at the end of the arrayyes, that's what I'm trying to do, thanks for clarifying Luis!
Aleksandr, I see how's that can be confusing...maybe i should fix it up 🤔
Great article!
Something for beginners (I'm pretty sure you already knew about this):
One hacky way to add an empty item to an array (if we can even call it appending an item to an array, I think more appropriate term would be resizing) would be:
However you should never ever do this.
Yes! Good one, let me add it to my notes 💪 Thanks for sharing 😀
You can also use it to shrink array
WOOO! never thought of that! Adding to my notes!!! thanks for sharing 😁
The point about not mutating if you need the array elsewhere is a good one, especially for parallel or concurrent programming. Even in single threaded JavaScript you might have passed an array by reference and so mutate things unexpectedly. Generally I find non-mutation to be a more relaxing method!
Yes, great point John! Let me add that to my notes! Thanks for sharing 👏
Great stuff, thanks for sharing!
You're welcome! Thanks for reading my article 🙂
Nice article!
Thanks! Glad you found it helpful 🙂
Great post :)
Every time i read a post with "X ways to do something" i remember when i started to learn Golang then i start laughing.
Do say more, what's Golang like? 😃
great post, keep going
You bet! Thanks for the encouragement! 🙌