0

I have an array with several objects within. I want to retrieve the object with the property called types, which is an array, having an entry called "zoom". Here is what the array of objects looks like:

[Object, Object, Object]
0: Object
1: Object
2: Object
  exclude: "0"
  file: "/m/a/max_wind_zoom.jpg"
  position: "7"
  types: Array[1]
     0: "zoom"

So I want to only extract object 2 in this case since its property types has an entry zoom.

I'm really puzzled as how to achieve this.

1 Answer 1

2

You can use Array.prototype.filter and Object.prototype.hasOwnProperty

[Object, Object, Object].filter(function (o) {
    return o.hasOwnProperty('types') && o.types.indexOf('zoom') > -1;
})
Sign up to request clarification or add additional context in comments.

1 Comment

Or just return o.types && o.types.indexOf('zoom') > -1;

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.