1

I want to put the data in the desired location. I want to add values ​​in the array. But I have no idea how to deserve this. Please advise me!

for example,I'll put in the second position data.

before

var arr=["1","2","3"];

after

var arr=["1","2","@","3"];

1 Answers1

1

You're looking for the .splice() method for arrays. Read about it here.

For your example, it would be something like

arr.splice(2,0,'@')

This says "go to element 2 of the array, remove 0 elements, and add the element '@'".

flowstoneknight
  • 1,248
  • 1
  • 7
  • 6