No, you can't use indexOf for that: it uses strict equality for the comparison, and therefore:
console.log({id: 1, name: 'milan'} === {id: 1, name: 'milan'}); // false
Because they're two different object, that contains the same property.
In the close future, you will be able to use the new ES6 Array's method like find
and findIndex
(they're already implemented in Firefox Nightly for example):
var myArray = [{id: 1, name: 'milan'}, {id: 2, name: 'rome'}];
var idx = myArray.findIndex(({id}) => id === 1); // `idx` will be `0`
var item = myArray.find(({id}) => id === 1); // `item` will contains {id: 1, name: 'milan'}
In the mean time, you have to do that manually; and if you want to compare all the properties is better if you create a deepEqual
function or similar.