how set value in javascript to Associative Arrays?
Why in this case i get error: "car[0] is undefined"
var car = new Array();
car[0]['name'] = 'My name';
Because you never defined car[0]
. You have to initialize it with an (empty) object:
var car = [];
car[0] = {};
car[0]['name'] = 'My name';
Another solution would be this:
var car = [{name: 'My Name'}];
or this one:
var car = [];
car[0] = {name: 'My Name'};
or this one:
var car = [];
car.push({name: 'My Name'});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With