var a = [ 'Child' , 'Adult'];
var b = [2,6];
var c = {}
for(var i=0; i<a.length; i++){
c[a[i]] = b[i]
}
document.getElementById('result').innerHTML = JSON.stringify(c, 0, 4);
<pre id="result"></pre>
Above loop produced
{
"Child": 2,
"Adult": 6
}
but how to produce the resutl like this
[{"child":2},{"Adult":6}]
which later on is easy for me to loop through.
[{"child":2},{"Adult":6}]it's not a valid edit to improve the expected result format to something like{"type":"child", "pax":2}if not explicitly requested by OP.awere something like["Child", "Child", "Adult"], a simple flat object would only be able to handle a unique array, and for-in can handle the nested iteration.