Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

JavaScript: shift: Remove first element from array

shift function is used to remove an Element from Array.

Syntax
arrayName.shift()

array.html





Array



"text/javascript">
var array = [2];

function printArray(arr) {
document.write("
Elements in Array are : "
);
for (var i = 0; i arr.length; i++) {
document.write(arr[i] + " ");
}
document.write("
"
);
}

printArray(array);

document.write("
Pushing element"
);
array.push(3);
printArray(array);

document.write("
Pushing element"
);
array.push(5);
printArray(array);

document.write("
Pushing element"
);
array.push(7);
printArray(array);

document.write("
Pushing element"
);
array.push(11);
printArray(array);






Open above page in browser, you can able to see following data.


Elements in Array are : 2 3 5 7 11

Removing first element
Elements in Array are : 3 5 7 11

Removing first element
Elements in Array are : 5 7 11

Removing first element
Elements in Array are : 7 11

Removing first element
Elements in Array are : 11



Previous                                                 Next                                                 Home


This post first appeared on Java Tutorial : Blog To Learn Java Programming, please read the originial post: here

Share the post

JavaScript: shift: Remove first element from array

×

Subscribe to Java Tutorial : Blog To Learn Java Programming

Get updates delivered right to your inbox!

Thank you for your subscription

×