The original question has been updated for clarity. The desired output is to merge an array of objects into a single object with specific conditions.
I am attempting to consolidate three sets of keys per object into one instance, choosing the lowest number for the Rank value or '-' if all Ranks are '-'
Below is sample data:
let objs = [
{
Keyword: 'A keyword',
'First Rank': '-',
'Second Rank': '-',
'Third Rank': 1,
},
{
Keyword: 'A keyword',
'First Rank': '-',
'Second Rank': 2,
'Third Rank': '-',
},
{
Keyword: 'A keyword',
'First Rank': '-',
'Second Rank': '-',
'Third Rank': 7,
}
]
// Code to filter and merge the objects...
Currently struggling to include objects with no values in the final merged result. Desired output shown below:
{
'Keyword': 'A keyword',
'First Rank': '-',
'Second Rank': 2,
'Third Rank': 1,
}
Any suggestions on how to achieve this? Thank you!