18

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!

0

1 Answer 1

18

What you want is the splice function:

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

Sign up to request clarification or add additional context in comments.

2 Comments

excelent! this is what I was searching for. Thank you!
arr.splice(1, 0, 'B');

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.