Quelle est la meilleure méthode pour obtenir l'index d'un tableau contenant des objets?
Imaginez ce scénario:
var hello = {
hello: 'world',
foo: 'bar'
};
var qaz = {
hello: 'stevie',
foo: 'baz'
}
var myArray = [];
myArray.push(hello,qaz);
Maintenant, je voudrais avoir l' indexOfobjet dont la hellopropriété est 'stevie'qui, dans cet exemple, serait 1.
Je suis assez novice avec JavaScript et je ne sais pas s'il existe une méthode simple ou si je dois créer ma propre fonction pour le faire.
var elementPos = array.map(function(x) {return x.id; }).indexOf(idYourAreLookingFor); var objectFound = array[elementPos]; [link] ( stackoverflow.com/a/16100446/1937255 )
helloetqaz?