I have an array of objects of which I then try to see if an object exists in that array, I have used Array#includes
which always gives me false
and Array#indexOf
which always gives me -1
, I tried using $.inArray
of jQuery however I'm using React Native which doesn't support jQuery.
The thing is the objects look exactly the same and should be the same as I'm just passing the data around, my logs:
Array:
Array [
Object {
"age_range": Object {
"min": 21,
},
"city": "San Francisco",
"first_name": "Michelle",
"gender": "male",
"id": "1798537990447153",
"last_name": "West",
"locale": "en_GB",
"name": "Michelle West",
"option": "Option 5",
"picture": Object {
"data": Object {
"height": 236,
"is_silhouette": false,
"url": "https://scontent.xx.fbcdn.net/v/t1.0-1/10430919_1383337475300542_6783404984861635685_n.jpg?oh=0d76f0c209288149c0fb3cd4f09c211a&oe=5AD1C732",
"width": 236,
},
},
"sub": "Hjj",
"uid": "xx",
"updated_time": "2016-08-16T16:48:59+0000",
"verified": false,
},
]
Object:
Object {
"age_range": Object {
"min": 21,
},
"city": "San Francisco",
"first_name": "Michelle",
"gender": "male",
"id": "1798537990447153",
"last_name": "West",
"locale": "en_GB",
"name": "Michelle West",
"option": "Option 5",
"picture": Object {
"data": Object {
"height": 236,
"is_silhouette": false,
"url": "https://scontent.xx.fbcdn.net/v/t1.0-1/10430919_1383337475300542_6783404984861635685_n.jpg?oh=0d76f0c209288149c0fb3cd4f09c211a&oe=5AD1C732",
"width": 236,
},
},
"sub": "Hjj",
"uid": "xx",
"updated_time": "2016-08-16T16:48:59+0000",
"verified": false,
}
When using a tool to double check only thing I noticed were some spacing differences maybe cause by different editors, all I'm doing is Arr.includes(obj)
, what could be causing the problem please and how do I correctly identify if that object exists?