Saturday, 16 September 2017

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

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...