Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add items to a nested Array?

Say I have an array such as this in Javascript:

var cars = { vendor: [ { type: [ 'camry', 'etc' ] } ] } 

In Javascript what command can I use to add an item to type... For example if I wanted to have a text box that a user can place text into and then hit a button that will add the item into the array. The item that would be added would need to be placed in with the same items as "camry" and "etc". Thanks!

like image 592
amlane86 Avatar asked May 14 '26 10:05

amlane86


1 Answers

Try something like

cars.vendor[0].type.push("foo");

Where "foo" is your data to add.

like image 117
jack Avatar answered May 16 '26 00:05

jack



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!