CodesJava

Easy learning with example program codes

JavaScript Array shift() method

The JavaScript array shift() method is used to remove and returns the first element of an array.

Note: The length of the original array will be modified.

Syntax:

array. shift()

Return:
The first element of an array.

Example:

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

Output:

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








Copyright © 2019 CodesJava DMCA.com Protection Status