0

I have this array of objects main_obj = [{ name: "Jason", age: 10 }, { name: Jeff, age: 22}];

How can I get the age of Jason using Lodash? I tried _.map(main_obj, 'Jason') but didnt work.

1
  • 1
    you could use _.find() Commented Apr 9, 2020 at 14:51

1 Answer 1

0

Use lodash find() to search for the object where name = "Jason". Use 'his' object to get the .age

var main_obj = [{ name: "Jason", age: 10 }, { name: "Jeff", age: 22}];
var Jason = _.find(main_obj, { name: 'Jason' });
console.log(Jason.age);
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.0.0/lodash.js"></script><script src="http://gh-canon.github.io/stack-snippet-console/console.min.js"></script>

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

Comments

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.