Saturday, August 25, 2018

Javascript: Unshift to second position of the array





I understand this diagram:



Unshift/Push diagram



But now my question is... How can I add an element just in the second position of the Array?



If I have this array: (A, C, G, T) and I want to add B...



The result that I want should be: (A, B, C, G, T)




Any suggestions?



Thank you!


Answer



What you want is the splice function:



arr.splice(index, 0, item); will insert item into arr at the specified index.


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...