Javascript Array add Items to Array by index

Description

Javascript Array add Items to Array by index



let animals = new Array("dog","cat","seal","walrus","lion", "cat");

// splice in new element
animals.splice(animals.lastIndexOf("cat"),1,"monkey"); // dog,cat,seal,lion,monkey

console.log(animals);//from   w w w  . j  a  va2s . c o m



PreviousNext

Related