DEV Community

william Wang
william Wang

Posted on

Js Fundamentals: Array.prototype.pop(), push(), shift(), and unshift()

1.push(), adds one or more elements to the end of an array and return the new length;
example:
Image description

2.pop(), removes an element from the end of an array and returns that item;
example:
Image description

3.unshift(), add one or more elements to the beginning of an array and returns the new length;
example:
Image description
add more elements:
Image description

4.shift(), removes an element from the beginning of an array and returns that element.
example:
Image description

Top comments (0)