// Creating an Array and Initializing with Values let courses = ["HTML", "CSS", "Javascript", "React", "Node.js"]; console.log("Original Array: " + courses); // Removes and returns the last element let lastElement = courses.pop(); console.log("After Removing the last elements: " + courses); // Removes and returns the first element let firstElement = courses.shift(); console.log("After Removing the First elements: " + courses); // Removes 2 elements starting from index 1 courses.splice(1, 2); console.log("After Removing 2 elements starting from index 1: " + courses);
Original Array: HTML,CSS,Javascript,React,Node.js After Removing the last elements: HTML,CSS,Javascript,React After Removing the First elements: CSS,Javascript,React After Removing 2 elements starting from index 1: CSS
pop(), shift(), or splice() JavaScript.
Working Code Asked question August 26, 2024