What is pop method in javascript?

Javascript array pop method:

pop(): means it's remove value in the our array from the last index and return with new index.

pop() example:

<script>
const colors = ["Red", "Green", "blue", "Black", "Orange", "White", "Coffee"]
console.log(colors.pop());
// "Coffee"
console.log(colors.length);
// "6"

console.log(colors);
// Array ["Red", "Green", "blue", "Black", "Orange", "White"]
colors.pop();
console.log(colors.length);
// "5"

console.log(colors);
// Array ["Red", "Green", "blue", "Black", "Orange"]
</script>

This method is same as shift() but from the first index.





No comments:

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

Copyright Reserved to Anything Learn. Powered by Blogger.