Vasin Noppaket Vasin Noppaket - 2 months ago 5
Javascript Question

Looping Object javascript

How can I build a loop in JavaScript?

var input = {0:['S','M','L','XL'],1:['Red','Blue','Black']};
var output =
{
0:['S','Red'],
1:['S','Blue'],
2:['S','Black'],
3:['M','Red'],
4:['M','Blue'],
5:['M','Black'],
6:['L','Red'],
7:['L','Blue'],
8:['L','Black'],
9:['XL','Red'],
10:['XL','Blue'],
11:['XL','Black'],
};


I will render Html from output

Answer

You are trying to mix object and array. Hope you want something similar to the following.

var ina = ['S','M','L','XL'], inb= ['Red','Blue','Black'];
var c=[];
ina.map(x=>inb.map(y=>c.push([x, y])));
c.map(x=>console.log(x));
Comments