While I understand that the following structure will not maintain order if iterated upon, I don't understand why the id++
works. I would think that incrementing the id
is dependent on a structure that maintains order like an array. How is it smart enough to increment? I can't find the documentation. Please help.
let id = 0;
const cars = {
"ford": {
"model": "focus",
"id": id++
},
"honda": {
"model": "civic",
"id": id++
},
"toyota": {
"model": "corolla",
"id": id++
}
}
console.log(cars);
{
ford: { model: 'focus', id: 0 },
honda: { model: 'civic', id: 1 },
toyota: { model: 'corolla', id: 2 }
}