javascript-Array

splice 剪切和替换功能

var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.splice(2, 0, "Lemon", "Kiwi");
//Banana,Orange,Lemon,Kiwi,Apple,Mango

array.splice(index,howmany,item1,.....,itemX)

  var fruits = ["Banana", "Orange", "Apple", "Mango"];
  fruits.splice(2, 1, "Lemon", "Kiwi");
  //Banana,Orange,Lemon,Kiwi,Mango

var fruits = ["Banana", "Orange", "Apple", "Mango", "Kiwi"];
fruits.splice(2, 2);

// Banana,Orange,Kiwi

你可能感兴趣的:(javascript-Array)