How to transform object object?

var object = [
 {0:{text: "Abbeville", value: "230"}},
 {1:{text: "Abernant", value: "231"}}
];


var option = [
 {text:'Abbeville', value:230},
 {text:'Abernant', value:231}
];
March 12th 20 at 08:06
2 answers
March 12th 20 at 08:08
Solution
const option = object.map(obj => Object.values(obj)[0])

If it is expected that there may be incorrect data instead of an object, do an additional check.
But I think you need sorting on this index?
March 12th 20 at 08:10
Solution
var object = [
 {0:{text: "Abbeville", value: "230"}},
 {1:{text: "Abernant", value: "231"}}
];

const option = object.reduce((p,c) => {
 const e = Object.values(c)[0];
 p.push({text: e.text, value: parseInt(e.value)});
 return p;
}, []);

Find more questions by tags JavaScript