Because you never defined car[0] . You must initialize it with a (empty) object:
var car = []; car[0] = {}; car[0]['name'] = 'My name';
Another solution would be the following:
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'});
source share