Question: Using [underscore.js](http://underscorejs.org/#collections), what is the simplest way to get the **ID** of the object with the person named "Ted"?

**Example:**

```
var people = {
  1: { name: "Ted" },
  2: { name: "Will" },
  3: { name: "James" }
}

```

**Raw JS solution:**

```
var personId;

for (id in people) {
  if (people[id].name === "Ted") {
    personId = id;
  }
}

```

Answer: 
With [`findKey`](http://underscorejs.org/#findKey):

```
var personId = _.findKey(people, function(obj) { return obj.name === 'Ted' });

```

Blender suggests this simplified version:

```
var personId = _.findKey(people, { name: 'Ted' });

```
In case there are several id with the same name, I propose you a raw JS solution that gives you an object inside only remains properties matching :

```
var people = {
  1: { name: "Ted" },
  2: { name: "Will" },
  3: { name: "James" },
  4: { name: "Ted" }
};
var keys = Object.keys(people);
result = {};
keys.forEach(item => {if (people[item].name === "Ted")result[item] = {name: people[item].name}});
console.log(result); // { '1': { name: 'Ted' }, '4': { name: 'Ted' } }

```