How object equality checks work in Javascript? [duplicate]

丶灬走出姿态 提交于 2020-02-07 00:00:27

问题


I'm trying to check for the existence of an element of an array using built-in Javascript array function

const routes = [
  { path: 'users/:id', component: 1 },
  { path: 'users', component: 2 },
  { path: 'todos', component: 3 },
  { path: '', component: 4 }
];

console.log(routes.indexOf({ path: 'users', component: 2 }));
console.log(routes.indexOf(routes[1]));
console.log(routes[1] === { path: 'users', component: 2 });

But it is returning results that aren't useful for my objective at all:

-1
1
false

My actual objects are more complex than the example, but this is gives similar behavior

来源:https://stackoverflow.com/questions/59532726/how-object-equality-checks-work-in-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!