Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
I have some code like this:
var array=[[[[[[1],2],3],4],5],6]
I know how to retrieve the innermost array, but I don't know how to push a new array [0] into the innermost array.
Is this possible?
1
I suppose you want to add new inner-most array on the first position. You can use unshift function:
array[0][0][0][0][0].unshift([0]);
Add a comment
Try this one
var array=[[[[[[1],2],3],4],5],6]; function pushNew(arr, newElement){ if(arr[0].length === 2){ pushNew(arr[0], newElement); } else { arr[0].unshift([newElement]); } } pushNew(array,0);
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
1, you can just assign another array to that same reference.