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.

asked Jul 13, 2020 at 1:24

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);

answered Jul 13, 2020 at 1:26
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

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.