Lian Nivin
Lian Nivin

Reputation: 35

Delete object for a nested array (Javascript)

Based on an object like this:

var p = [
           {x: [
                 {x1: 1}, 
               ]
           },
           {x: [
                 {x1: 2},
               ]
           }
        ];

I need to filter p objects when x1 is different from 1:

var p = [
           {x: [
                 {x1: 2},
               ]
           }
        ];

Thanks in advance.

Upvotes: 1

Views: 59

Answers (1)

Adrian Brand
Adrian Brand

Reputation: 21658

var p = [
           {x: [
                 {x1: 1}, 
               ]
           },
           {x: [
                 {x1: 2},
               ]
           }
        ];

const results = p.filter(val => !val.x.some(v => v.x1 === 1));

console.log(results);

Upvotes: 3

Related Questions