score:6

Accepted answer

my solution would be

    var arr= [
    {
        "key":"CES0000000001",
        "25568.95655":"29923",
        "25568.96078":"31603"
    },
    {
        "25568.96501":"34480",
        "25568.96924":"38347"
    }
];

var transformed= arr.map(function(obj){
    var result= {
        key: obj.key,
        values: []
    }

    for (var key in obj) {
      if (obj.hasOwnProperty(key) && key !== "key") {
          result.values.push([key, obj[key]]);
      }
    }
    return result;
});

console.log(transformed);

score:2

This is an old post I see, but I want to share how you could do this with es6 object destructuring and restructuring. if you have an object...

const obj1 = {
    "key":"CES0000000001",
    "25568.95655":"29923",
    "25568.96078":"31603"
};

you could have:

const restructure = ({key, ...values}) => ({key, Object.entries(values)});
const obj2 = restructure(obj1);

or for the array you could restructure all of them with:

const b = arr.map(({key, ...values}) => ({key, Object.entries(values)}));

or if you are reusing the function...

const b = arr.map(restructure);

Related Query

More Query from same tag