1

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.

1 Answer 1

3

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

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

console.log(results);

Sign up to request clarification or add additional context in comments.

4 Comments

Would you mind adding a response for strings values? It would be great. Thanks.
What sort of string response?
I mean how can I use a different method than some. In some case that uses strings instead of 1 and 2 or any number.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.