Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert something in the array?

If I have for example this array-variable:

var arr=[  
[1,2,3]  
[4,5,6]  
]  

How can I insert something in that array, for example like this:

arr=[  
[1,2,3]  
[4,5,6]   
[7,8,9]  
] 

I tried arr=[arr,[7,8,9]] but then the [] are building up.

How to do this?

like image 365
SmRndGuy Avatar asked Mar 05 '26 01:03

SmRndGuy


1 Answers

arr.push([7,8,9]);

That should do the trick. If you want to insert:

arr.splice(offset,0,thing_to_insert);
like image 77
Niet the Dark Absol Avatar answered Mar 07 '26 14:03

Niet the Dark Absol



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!