How to use array unshift in JavaScript
In this article I am going to explain about unshift method in JavaScript.
Array unshift method in JavaScript
The array unshift method is used to inserting element in the starting position.
Syntax of unshift method
array.unshift(element1,...........,elementN);
|
Parameters in unshift method:
Return value of unshift method
unshift method returns the length of new array.
Example of unshift method
<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">
var val = new Array("one", "two", "three", "four");
var length = val.unshift("First");
document.write("Now array is : " + val);
document.write("<br /> Length of the array is : " + length);
</script>
</body>
</html>
|
Output:
Ask Your Question
Got a programming related question? You may want to post your question here