Answers for "How To Insert An Item Into An Array At A Specific Index In JavaScript"

0

How To Insert An Item Into An Array At A Specific Index In JavaScript

var arr = [];
arr[0] = "Apple";
arr[1] = "Grape";
arr[2] = "Pear";
arr[3] = "Peach";
arr[4] = "Grapefruit";

console.log(arr.join()); // Apple,Grape,Pear,Peach,Grapefruit
arr.splice(2, 0, "Orange");
console.log(arr.join()); // Apple,Grape,Orange,Pear,Peach,Grapefruit
Posted by: Guest on September-25-2021

Code answers related to "How To Insert An Item Into An Array At A Specific Index In JavaScript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language