Skip to content Skip to sidebar Skip to footer

Json Array Conversion Into Multi Dimension Array

I am new to Javascript and trying to convert data that I am getting from mongodb into multi dimension array like example below. If this could have been simple conversion of values

Solution 1:

You can put the array through Array.protoype.map, which replaces each value in the array with whatever the callback function returns. In the callback function you can return an array version of the object.

For example:

var result = yourArray.map(function (item) {
    return [item.text, item.count];
});

More array methods can be found on the MDN docs for Arrays.

Post a Comment for "Json Array Conversion Into Multi Dimension Array"