An Easy Solution for Array Methods in JavaScript
Common Array Methods
push()— adds an element to the end of the array.pop()— removes the last element.shift()— removes the first element.unshift()— adds an element to the beginning.slice(start, end)— returns a shallow copy of a portion of the array.splice()— adds/removes elements at any position.indexOf()— finds the position of an element.join()— combines all elements into a string.
let arr = [1, 2, 3];
arr.push(4); // [1, 2, 3, 4]
arr.pop(); // [1, 2, 3]
console.log(arr.join("-")); // "1-2-3"
Ready to master real-world JavaScript development?
Learn JavaScript hands-on with mentor-led, live sessions.