How can I convert the following object:
{
Value1: 1,
Value2: 3
}
into an array that looks like this:
[
{name: Value1, position: 1},
{name: Value2, position: 3}
]
I've tried using Object.keys, but didn't really get the desired results.
function convertToArray(obj){
return Object.keys(obj).map(prop => {
return {
name: prop,
position: obj[prop]
};
});
console.log(convertToArray({ Value1: 2}));