I have this javascript object:
{"Vanilla": 36, "Chocolate": 50, "Stracciatella": 24, "Coffee": 18}
to which I would like to "add" this array:
["Vanilla", "Amarena", "Chocolate", "Pistachio"]
The result I want is this:
{
"Vanilla": 37,
"Chocolate": 51,
"Stracciatella": 24,
"Coffee": 18,
"Amarena": 1,
"Pistachio": 1
}
This is what I have tried:
var me = ["Vanilla", "Amarena", "Chocolate", "Pistachio"]
var all = {
"Vanilla": 36,
"Chocolate": 50,
"Stracciatella": 24,
"Coffee": 18
}
var keys = Object.keys(all);
for (var i = 0; i < me.length; i++) {
if (me[i] in keys) {
console.log("keys:" + keys + " - " + me[i] + " in keys");
} else {
console.log("keys:" + keys + " - " + me[i] + " not in keys");
};
}
console.log(keys);