How to loop list with another list .The number of counts are same inside each list
List1 =[a,b,c,d]
List2 =[e,f,g,h]
Output
a
e
b
f
c
g
d
h
How to loop list with another list .The number of counts are same inside each list
List1 =[a,b,c,d]
List2 =[e,f,g,h]
Output
a
e
b
f
c
g
d
h
I would create a dictionary for this
const list = { a: ['e'], b: ['f'], c: ['g'], d: ['h'] };
and then do this in react.
Object.keys(list).map((key) => {
return list[key].map((val) => {
return `${key} \n ${val}`;
})
.join('\n');
})
.join('\n');
Updated*: As you've asked to you would create this dictionary considering that both the list will be of same length and no duplicates, this is how I would do it.
const l1 = ['a','b','c','d'];
const l2 = ['e','f','g','h'];
let l3 = {};
l1.forEach((v, i) => {
l3[v] = l2[i];
});