0

Here is my Array containing Objects, each Object has a ticker value:

[Object]
0: Object
    $$hashKey: "object:130"
    tags: Array[1]
    ticker: Object
        company: "Alcoa Inc."
        direction: "negative"
        percent: -3.89
        price: 14.59
        selected: true
        ticker: "AA"

There could be several objects, how would one use the _lodash library to pull out the ticker.ticker values out of each Object?

enter image description here

I've looked at their each and find methods, but they are used on very basic arrays, with no documentation on how to target key value pairs inside.

_.each([1, 2, 3], alert);

_.reduce(list, iteratee, [memo], [context])

Ideally, what I'm trying to do is take that Array, and produce something like:

ticker1 = ticker1, & ticker2 = ticker2 or

[ticker1, ticker2]

2 Answers 2

2

You can use _.pluck: https://lodash.com/docs#pluck

console.log(_.pluck(_.pluck(list, 'ticker'), 'ticker'));

http://jsfiddle.net/kevinle/vj7e66zy/

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

Comments

0

You can provide a property path to pluck():

_.pluck(list, 'ticker.ticker');

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.