Skip to content Skip to sidebar Skip to footer

Converting An Array Object To Another Object-part 2 In Javascript

This is a follow up question of Converting an object into array .Now I would like to do a reverse engineering where I want to convert back the JOSN to the original format except it

Solution 1:

function yymmddToString(yymmdd) {
    var months = ['January', 'February', 'March', 'April' .....];
    var x = yymmdd.split('-');
    return months[parseInt(x[1], 10)] + ' ' + x[0];
}
var result = data1.reduce(function(result, datum) {
    var x = result[datum.name] = result[datum.name] || {};
    x[yymmddToString(datum.time)] = datum.value;
    return result;
}, {});

Post a Comment for "Converting An Array Object To Another Object-part 2 In Javascript"