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

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -