1

I've to use lodash for get the values of this object: http://pastebin.com/raw.php?i=U1Z8tzY0

As you can see, I have one big object. I need to get all the autonomias names with the activo property set to true".

I've tried to use a lot of functions without result. I'm stuck.

And I can't find the way to do it properly after few days.

2
  • What is the expected output? Commented May 18, 2015 at 9:19
  • I expect all the autonomias with the activo: true: { "andalucia", "aragon", "asturias", "canarias", etc }. In this file all is set to true, but in a near real example some "autonomias" are going to set to false. Commented May 18, 2015 at 9:38

1 Answer 1

1

The following snippet should do the trick:

var res =  _(data)
             .chain()
                .result('autonomias')
                .filter({ activo: true }) 
                .pluck('name')
             .value();

Here is a demo.

You could also use native Array methods:

var res = data.autonomias.filter(function (el) {
    return el.activo === true;
}).map(function (el) {
    return el.name;
});
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks you!, I finally made my solution, but your is really better.
I know, but needed to use lodash. Thanks you.
what if I need to get the full object instead only the name of an active autonomia?
Thank you. Saved a lot of time.

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.