I am looking for this logic if possible in ES6 to combine 2 array elements in single array.
Below is data coming from backend.
dataFromBackend = [
{
animal: 'Elephant',
height: 123,
weight: 456
},
{
animal: 'Elephant',
food: 'abc',
sleep: 'xyz'
},
{
animal: 'Tiger',
height: 123,
weight: 456
},
{
animal: 'Tiger',
food: 'abc',
sleep: 'xyz'
},
{
animal: 'Rabbit',
height: 123,
weight: 456
}
]
Expected Output
convertedData = [
{
animal: 'Elephant',
height: 123,
weight: 456,
food: 'abc',
sleep: 'xyz'
},
{
animal: 'Tiger',
height: 123,
weight: 456,
food: 'abc',
sleep: 'xyz'
},
{
animal: 'Rabbit',
height: 123,
weight: 456,
food: 'No Data',
sleep: 'No Data'
}
]
And if there is no data for certain property I have to insert 'No Data'