0

My results for below code are:

--> ZZZ,Banana,Orange,Apple,Mango
--> ZZZ,ZZZ,Banana,Orange,Apple,Mango
--> ZZZ,ZZZ,ZZZ,Banana,Orange,Apple,Mango
--> ZZZ,ZZZ,ZZZ,ZZZ,Banana,Orange,Apple,Mango
--> ZZZ,ZZZ,ZZZ,ZZZ,ZZZ,Banana,Orange,Apple,Mango

I want the splice item index to increment along with the loop, but i in splice is always equal to 0 , please help?

  var fruits = ["Banana", "Orange", "Apple", "Mango"];
  var proto = fruits
  var i = 0
  a = []
  for (i = 0; i < 5; i++)
  {
  proto.splice(i,0,"ZZZ")

  debug(proto);
  }
IanO.S.
  • 1,362
  • 1
  • 10
  • 20
  • So I see that I can use proto.splice(i++,0,"ZZZ") , in order to increment, but now dealing with the issue of assigning the result of proto.splice(i++,0,"ZZZ") to a variable – IanO.S. May 23 '14 at 16:08
  • just used [http://stackoverflow.com/questions/586182/insert-item-into-array-at-a-specific-index][1] much better than splice for this [1]: http://stackoverflow.com/questions/586182/insert-item-into-array-at-a-specific-index – IanO.S. May 23 '14 at 16:25

0 Answers0