I have the following object
\"data\":{
\"name 1\":\"a\",
\"name 2\":\"b\",
\"name 3\":\"b\",
},
How can
you can get all the keys in the object in an array using Object.keys
function and use map
function to get the desired output.
This will convert to array of objects that will keep both the name and data.
var data = {
"name 1":"a",
"name 2":"b",
"name 3":"b",
}
var res = Object.keys(data).map(function(name){
var obj = {};
obj[name] = data[name];
return obj;
});
console.log(res);