Ads Top

What is shift method in javascript?

Javascript array shift method:

shift() remove element from the first index. Result will be return with new indexing.

shift() example:

<script>
const colors = ["Red", "Green", "blue"];

const firstColors = colors.shift();

console.log(colors);
// Array ["Green", "blue"]

console.log(firstColors);
// "Red"
</script>
 


Note: pop() remove element from the last index. 

No comments:

Note: Only a member of this blog may post a comment.

Copyright Reserved to Anything Learn. Powered by Blogger.