I have below array of objects,
var parsedData = [
{
"ID": "16",
"DESCRIPTION": "SMAATO"
},
{
"ID": "26",
"DESCRIPTION": "BIDSWITCH"
},
{
"ID": "1572",
"DESCRIPTION": "BIDSWITCH"
}
]
i have removed duplicate from this using below code,
var flags = [], l = parsedData.length, i;
for( i=0; i<l; i++) {
if( flags[parsedData[i].DESCRIPTION]){
if(attribute.toLowerCase() == "supply"){
console.log("coming!!"+parsedData[i].ID+"---"+parsedData[i].DESCRIPTION);
}
continue;
}
flags[parsedData[i].DESCRIPTION] = true;
groups_array.push({
id: parsedData[i].ID,
text: parsedData[i].DESCRIPTION
});
}
but what i need to achive is, if id is differnt and description same means need to append id to first one and remove duplicate one like this,
[
{
"ID": "16",
"DESCRIPTION": "SMAATO"
},
{
"ID": "26,1572",
"DESCRIPTION": "BIDSWITCH"
}
]
How to get this one help me please...
asked Jul 4, 2020 at 18:35
Harifrais
471 gold badge5 silver badges20 bronze badges
1 Answer 1
Try:
if (flags[parsedData[i].DESCRIPTION]) {
let id = groups_array.map(item => item.text).indexOf(parsedData[i].DESCRIPTION);
groups_array[id].id = groups_array[id].id + "," + parsedData[i].ID
continue;
}
Abito Prakash
4,8002 gold badges16 silver badges28 bronze badges
Sign up to request clarification or add additional context in comments.
2 Comments
Harifrais
Thanks Its working.But the arrow function will support in all browsers?.In IE its not working.
Ambu
If I'm not wrong, you can replace arrow function with: function(item){return item.text}. I've no idea If it'll work in all browsers, it's beyond my expertise, but googling 'arrow function browser support' should help. Perhaps, the details might be a topic for another, new SE question.
lang-js