CodesJava

Easy learning with example program codes

JavaScript Array unshift() method

The JavaScript array unshift() method is used to add one or more elements at the starting index of the given array.

Syntax:

array.unshift (element1,element2,....)

Parameters:
element1,element2,… : The elements to be added in a given array.

Returns:
Original array with specific addition elements.

Example:

<!DOCTYPE html>
<html>
<body>
<script>  
var a = ["GOLD","SILVER","DIAMOND","RUBY","PLATINUM"]
var result=a.unshift("BRONZE");  
document.writeln(a);
</script>  
</body>
</html>

Output:

BRONZE,GOLD,SILVER,DIAMOND,RUBY,PLATINUM
Please follow and like us:
error








Copyright © 2019 CodesJava DMCA.com Protection Status