I have an object of key and values(array of objects)
Obj:{
key1: [{desc:'aaa', pos:0}, {desc:'bbb', pos:1}],
key2: [{desc:'ccc', pos:0}, {desc:'ggg', pos:1}],
key3: [{desc:'ddd', pos:0}, {desc:'jjj', pos:1}],
key4: [{desc:'eee', pos:0}, {desc:'kkk', pos:1}]
}
From the above...I need to get an array of objects for each key in the object. So,I need to get the desc property of a position 0 and assign to text1 below. The text2 and text 3 will be hardcoded.
data = [
{
text1: 'aaa',
text2: 'name2',
text3: '29/112/2017',
},
{
text1: 'ccc',
text2: 'name2',
text3: '29/12/2017',
},
{
text1: 'ddd',
text2: 'name2',
text3: '29/12/2017',
},
{
text1: 'eee',
text2: 'name2',
text3: '29/12/2017',
},
]
Tried the following but doesn't work...
var values = Object.values(obj); - would give me an array of array of objects
values.map((item, index) => {
item.map((i, x) => {
if(i.pos == 0)
{
return(
{
text1: i.desc,
text2: 'name2'
text3: '29/12/2017'
}
)
}
})
How would I get a structure like "data" array?