I've been having trouble to get this function to work with multiple properties and values.
the code here works fine as long as the object contains one property and value.
var arr = [ [{ prop: 'val1' }], [{ prop: 'val2' }], [{ prop: 'val3' }] ]
var res = arr.map(getObject);
function getObject(o) {
return Array.isArray(o) ? getObject(o[0]) : o;
}
console.log(res);
[
{
"prop": "val1"
},
{
"prop": "val2"
},
{
"prop": "val3"
}
]
- I'm trying to get the function to work so that it can log an object with multiple properties and values
ex.
oldArray = [ [{ prop1: 'val1', prop2: 'val2' }], [{ prop1: 'val1', prop2: 'val2' }], [{ prop1: 'val1', prop2: 'val2' }] ];
newArray = [
{
"prop1": "val1",
"prop2": "val2",
},
{
"prop1": "val1",
"prop2": "val2",
},
{
"prop1": "val1",
"prop2": "val2",
},
];