问题
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