Thursday, October 18, 2018

javascript - Push data into a certain position in an array




How do I push some data into a certain place in an array?



I am trying the code below:



Keys[1].push({ Keys: "Test" });


But it doesn't seem to work as expected


Answer




The method you are looking for is splice



arrayObject.splice(index,0,{Keys:"Test"});


https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice


No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...