Parse JSON array into different Object using Reduce I have an script that is receiving some JSON and then I am parsing it out using reduce.  I am sure there is a more elegant way to do it.

JSON

 var request = {
    "operation":"rate_request",
    // JSON removed to make more readable. 
    "freight":
    {
        "items":
        // here is the array I am targeting
        [{
            "item":"7205",
            "qty":10,
            "units":10,
            "weight":"19.0000",
            "paint_eligible":false
        },
        {
            "item":"7677",
            "qty":10,
            "units":4,
            "weight":"5.0000",
            "paint_eligible":false
        }],
    // more JSON removed
}


Here is function to parse out and then loop through:

function parseItems(json){
    var resultsReduce = new Object()
    var itemKeys = ['item','qty', 'units','weight', 'paint_eligable']
    itemKeys.forEach(function(item){  
        if (item){
            resultsReduce[item] = json.freight.items.reduce(function(array, object) {
                   return array.concat(object[item])
            }, [])
        }
    })
    var itemXML = ''

    for(var i = 0; i &lt; resultsReduce.item.length; i++){
        var weight = Number(resultsReduce['weight'][i])
        var qty = Number(resultsReduce['qty'][i])
        var units = Number(resultsReduce['units'][i])
        itemXML += '&lt;LineItem&gt;'
                + '&lt;PieceCount&gt;' + units * qty + '&lt;/PieceCount&gt;'
                + '&lt;NetWeight UOM="Lb"&gt;' + weight * qty + '&lt;/NetWeight&gt;'
                +'&lt;GrossWeight UOM="Lb"&gt;' + weight * qty + '&lt;/GrossWeight&gt;'
                + '&lt;FreightClassification&gt;' + '50' + '&lt;/FreightClassification&gt;'
                +'&lt;/LineItem&gt;'
    }
    return itemXML
}


The parseItems function turn the JSON into an object with arrays:

  {
 "item": [7205,7677],
 "qty": [10,10],
 "units": [10,4],
 "weight": ["19.0000","5.0000"],
 "paint_eligible": [false, false]
 }


Then the function loops through the object (manually by targeting the keys) and loops through the loop of the array. Like I mentioned, I am sure it can be more elegant. Any thoughts on how you would make it cleaner?
This can be handled with a single Array.prototype.forEach loop. Consider the following:

function parseItems(json){
  var output = '';
  json.freight.items.forEach(function (item) {
    output += `
      &lt;LineItem&gt;
        &lt;PieceCount&gt;${item.units * item.qty}&lt;/PieceCount&gt;
        &lt;NetWeight UOM="Lb"&gt;${item.weight * item.qty}&lt;/NetWeight&gt;
        &lt;GrossWeight UOM="Lb"&gt;${item.weight * item.qty}&lt;/GrossWeight&gt;
        &lt;FreightClassification&gt;50&lt;/FreightClassification&gt;
      &lt;/LineItem&gt;`;
  });

  return output;
}


No need to iterate over everything repeatedly for this.

Edit: Made a fiddle for you