2

I have a json array like this :

myArray=[{ a:1,
          b:[{c:"x",d:"y"}, {c:"r", d:"s"}...]
         },
         { a:2,
          b:[c:"p",d:"q"}, {c:"x", d:"s"}...]
         }
         ...
        ]

Is it possible to get a subset of myArray with unique values of "c" using underscore.js?

1 Answer 1

18

This should do it:

_.chain(myArray)
 .pluck("b")
 .flatten()
 .pluck("c")
 .unique()
 .value()
Sign up to request clarification or add additional context in comments.

1 Comment

Awesome, it works!, never thought it would be possible with the chain of functions like you suggested. Thanks!

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.