Last Updated : Jan 1, 2023
Here it is - array.push(item1, item2, ..., itemX)
Here, from above syntax we see that first we have to give name or array before push after push inside round braces we have to add the objects which we want to add inside array.
- If you don’t know anything from the above you can visit our article, in which you can learn these concepts easily from our experienced developers.
- Now, One thing we said that there are many ways with help of which you are albe to do this. and in this article we use push() method. Whereas the another method is unshift() method. We will learn about this method in our next article. So, without wasting time let us understand our today’s concept of array push().
- Now, above we see in script tag that we create an array with some items or objects inside that. After this, we also show the items inside of array with the help of console method. Now, after that we use array push method to add an object inside array using name of the array and the objects which we want to add inside array. you can also see the syntax of push() method above.
- Now, as you see we add an object with name Mercedes inside an array having name array. After that we just console the array after pushing object in it to show that object is successfully added inside array.
- Here, at end one question stuck in mind that is how we are able to add object at any position inside array because using push method we are able to add object only at last. So, this is an assignment for you all until we will meet in next tutorial. We hope you easily understand the codes given above with the help of these steps easily.