JavaScript Filter a list in list and preserve structure list filter list,list filter list java,filter list by

If you are okay with mutating the array, you could update bar with the filtered objects:

const foo = [{id:1,bar:[{id:1,a:null},{id:2,a:224},{id:3,a:345},]},{id:2,bar:[{id:4,a:763},{id:5,a:null},{id:3,a:111},]}]

foo.forEach(o => o.bar = o.bar.filter(obj => obj.a !== null))

console.log(foo)
Answer:1

Since you are actually only filtering the inner array, then you want to use a map for the outer array.

const original = [
  {
    id: 1,
    bar: [ {id: 1, a: null}, {id: 2, a: 224}, {id: 3, a: 345}, ]
  },
  {
    id: 2,
    bar: [ {id: 4, a: 763}, {id: 5, a: null}, {id: 3, a: 111}, ]
  }
]

const result = original.map(elem => ({...elem, bar: elem.bar.filter(bar => bar.a !== null)}));

console.log(`result: ${JSON.stringify(result, null, 2)}`);


// Note: original array unchanged
console.log(`original (unchanged): ${JSON.stringify(original, null, 2)}`);
Answer:2

I am making a dark mode for a site using a button toggle. To keep the dark mode saved when changing pages, I am using cookies. When pressing the toggle again, the dark mode is disabled but is not ...

I am making a dark mode for a site using a button toggle. To keep the dark mode saved when changing pages, I am using cookies. When pressing the toggle again, the dark mode is disabled but is not ...

  1. isn't
  2. https://www.instagram.com/
  3. isnetworld
  4. instagram
  5. isn't she lovely
  6. isnt it romantic
  7. isna
  8. isn't it ironic
  9. isner
  10. isnull sql
  11. isn network
  12. isnac 2020
  13. isnt she lovely chords
  14. isns
  15. isnan
  16. isn't it
  17. isnull
  18. isn't it romantic cast
  19. isna excel
  20. disney plus

I am curently trying to make out one map to show my instagram photos. After some research i 've found this github rep https://github.com/turban/Leaflet.Instagram and here you can see exactly what ...

I am curently trying to make out one map to show my instagram photos. After some research i 've found this github rep https://github.com/turban/Leaflet.Instagram and here you can see exactly what ...

I am trying to use defaultChecked in reactjs when using map function to only one radio button. But How can I acomplish it? {colors.map((color, index) => { return ( <label ...

I am trying to use defaultChecked in reactjs when using map function to only one radio button. But How can I acomplish it? {colors.map((color, index) => { return ( <label ...

How to normal resize & drag UI Dialog in scrolled window/area? Is top/left correction of Dialog really necessary? (how to correct coordinates that both works) How about fixing Dialog? What ...

How to normal resize & drag UI Dialog in scrolled window/area? Is top/left correction of Dialog really necessary? (how to correct coordinates that both works) How about fixing Dialog? What ...