filmov
tv
How to add an element to the end of a JavaScript Array - Array.prototype.push()

Показать описание
In this video, I’ll explain how to add an element to the end of a JavaScript Array.
In JavaScript, the push method adds one element to the end of an array. I’m going to take this example code and paste it here in the browser. I don’t need the comments, and for now we simply want to define the array, and then I’ll add on to the end.
So can do it one more time. I’m going to use the push method to add one more element to the end of “foo.” So now it should have the letter “f” at the end of the array, as the last element, and the new length is six. And when I inspect “foo,” I see that it has six elements.
So, the push method will add whatever you pass to it to the end of an array. It will always make it the last element in the array, and it will return the new length of the array.
If you found this video helpful, you can subscribe to my channel by clicking the red "subscribe" button right under the video. And you can also visit my blog, where I have many more articles and tutorials about web development.
Thanks very much for watching.