Suppose I wanted to create a dictionary of, say, car makes to one or more models.
It seems that I could do this in two different ways in ES6.
1. Create an Object map:
Code:
const makesAndModels = {
"mazda": [
{ name: "Miata" },
{ name: "626" }
],
"toyota": [
{ name: "Camry" }
],
...
};
2. Create an ES6 Map instance:
Code:
const makes = {
mazda: { name: "Mazda" },
toyota: { name: "Toyota" }
};
const makesAndModels = new Map([
[makes.mazda, [
{ name: "Miata" },
{ name: "626" }
]],
[makes.toyota, [
{ name: "Camry" }
]],
...
]);
What are the key differences and pros/cons between the above two methods?