Array Push and Pop in JavaScript
Level 280 keystrokes
Uses push() to add an element to the end and pop() to remove the last element.
JavaScript code
// Create an array with three numbers1let arr = [1, 2, 3];// push() adds an element to the end of the array2arr.push(4);// Output: [1, 2, 3, 4]3console.log(arr);// pop() removes and returns the last element4arr.pop();// Output: [1, 2, 3]5console.log(arr);Output
[ 1, 2, 3, 4 ] [ 1, 2, 3 ]
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this JavaScript code and how often they appear.
;× 5.× 4(× 4)× 4,× 2[× 1]× 1=× 1