reactjs - Javascript indexOf object not found -


i'm trying find index of object inside array in javascript.

this code i'm using, this returns -1 it's not found. it's there

var index = this.state.users.indexof(user); 

the object i'm comparing identical one's in collection shown in picture below

enter image description here

i'm using code compare two

console.log(this.state.users[0]); console.log(member); 

so don't understand why giving negative result

in javascript object compared reference, such as

var obj1 = {prop: 0}; var obj2 = {prop: 0}; alert(obj1 === obj2); //false 

indexof compare this, isn't finding anything.

to find object in array identical given, can use array.prototype.filter method.

or ecmascript 2015 array.prototype.find method


Comments

Popular posts from this blog

Process 'command 'F:\android-sdk\build-tools\21.1.2\aapt.exe'' finished with non-zero exit value 1 -

apache - setting document root in antoher partition on ubuntu -

java - Updating to mongo 3.0 -