4

I have the following type of array of objects, which I saved as image for you all so its easier to see:

enter image description here

Now what I want from this massive array is all the objects who's investments status is complete.

using the _.where, I tried to do (data being the giant array you see in the image):

var something =  _.where(data, function(item){ 
    return item.investments[0].statues === "complete" 
});

But um nothing seems to happen ... What am I doing wrong? I want objects out of the array who's investments status is complete.

ideas?

2
  • Unless it's a typo, you have ._where instead of _.where. status is also misspelled. If that's really in your code that will cause the failure for sure Commented Nov 3, 2015 at 23:28
  • Fixed he spelling mistake sorry I didn't copy and paste the code like I should have >_> Commented Nov 3, 2015 at 23:30

2 Answers 2

9

I'd try out the filter method:

https://lodash.com/docs#filter

Iterates over elements of collection, returning an array of all elements predicate returns truthy for.

var results = _.filter(data, function(item){
  return item.investments.data[0].status === "complete";
});

And as BG101 mentioned: you didn't reference the data property of the investments object, so you were off a level.

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

Comments

6

try:-

_.filter(data, function(item) { 
   return item.investments.data[0].status === "complete";
});

you have a typo in status and investments is an object with a property data

2 Comments

A down vote 6 months later. even though the correct answer used it as the source. puzzling.
have another one

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.