Question: I have an array of objects and would like to check if a specific key/value exists, I'm currently using a for..in loop but was wondering if there is shorter/better way to do this?

**JS**

```
var models = [
  {
    "id": 1,
    "name": "James"
  },
  {
    "id": 2,
    "name": "Ken"
  },
  {
    "id": 3,
    "name": "Jason"
  }
];

function checkNameExists(name) {
    for( var model in models ) {
        if (models[model].name === name) {
            return true;
        }
    }
}

var nameExists = checkNameExists("Ken");

if(nameExists) {
    console.log('Name exists');
}

```

JSFiddle: <http://jsfiddle.net/kyllle/c21opmj8/1/>

Answer: 
Without depending on external libraries, `Array.filter()` does the job:

```
models.filter( (x) => x.name==="Jason" )

```

`Array.find()` finds first occurrence and stops, hence it's faster.
Here is a solution with underscore

```
console.clear();

var models = [
  {
    "id": 1,
    "name": "James"
  },
  {
    "id": 2,
    "name": "Ken"
  },
  {
    "id": 3,
    "name": "Jason"
  }
];

var tab_name = _.map(models, function(x){return x.name});
var name_exists = _.contains( tab_name , 'Ken')

if( name_exists ) {
    console.log('Name exists');
}

```