const fruits = ["Apple", "Banana", "Orange", "Mango", "Grapes"]; console.log("Original Array:", fruits); // Using slice() const slicedFruits = fruits.slice(1, 4); console.log("\nUsing slice:"); console.log("Sliced Array:", slicedFruits); console.log("After slice, Original Array:", fruits); // Using splice() const splicedFruits = fruits.splice(2, 2, "Pineapple", "Strawberry"); console.log("\nUsing splice:"); console.log("Removed Elements:", splicedFruits); console.log("After splice, Modified Array:", fruits);
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter