I have two lists,
l1= ["apple","banana","grape"]
l2 = ["red","yellow","black"]
How to make a list of this type? (a list of objects)
l3 = [
{fruit:"apple",colour:"red"},
{fruit:"banana",colour:"yellow"},
{fruit:"grape",colour:"balack"}
]
I tried something like this, but the output is not what I expected:
let l3 = [];
let Obj = {};
for (let l = 0;l<l1.length;l++) {
Obj = {};
for (h=0;h<l2.length;h++) {
Obj["fruit"] = l1[h];
Obj["colour"] = l2[h];
}
l3.push(Obj);
}
return l3;