Sunday, 6 September 2020

how to loop through nested objects and push fields after comparing them in javascript/es6

I have the following 3 items from the structure of data below:

how

  • Let's assume that group has three fields: id, name, accountNumber and because I have three items, two of them have the same accountNumber.

What i want to do

I want to write a function with javascript/es6 to loop through these objects, check the id and accountNumber in group and push that in a new array of objects named results. (If any id contains the same accountnumber it should not be pushed to the new array below)

# new array 
# results = [
{
    id: 1,
    accountNumber: 2289,
  },
  {
    id: 2,
    accountNumber: 9920,
  },
]

Because of my background with python i am struggling to accomplish this. any help would be very helpful.



from how to loop through nested objects and push fields after comparing them in javascript/es6

No comments:

Post a Comment