You could use the Object.keys() methods to iterate over your object and then use the Array.map() method to transform your object to the array structure you need.
var data = {
"0": "value1",
"1": "value2"
}
var newData = Object.keys(data).map(key => ({
[key]: data[key]
}))
console.log(newData)
–Update–
You would simply need to change the object being returned from the callback function passed to the .map()
method.
var data = {
"time_1": 20,
"time_2": 10,
"time_3": 40,
"time_4": 30
}
var newData = Object.keys(data).map(key => ({
"key1": key,
"key2": data[key]
}))
console.log(newData)
2
solved How to create multiple object using single object in JavaScript? [closed]