Javascript push() Method - Array Function

How to add new elements to the end of an array?
What is the use of push() function in javascript?

Explanation

Method: push() :
This function add new elements to the end of array and gives the length of the array as the return value
Syntax:
array1.push(element1,element2,...);

Example:


<script language="javascript">
var stack=["0","1"]
var leng = stack.push(2,3);
document.write(leng);
</script>

Result:


4

Thus, to add new elements, this method can be used.

Ask Questions

Ask Question