【发布时间】:2020-11-24 07:29:39
【问题描述】:
使用角度, 我有一个数组
list: Employee[] = [
{id: 1, name: "conrad", email: "conrad@test.com", password: "123456", department: "Admin"},
{id: 2, name: "two", email: "2@test.com", password: "123456", department: "Finance"},
{id: 3, name: "three", email: "3@test.com", password: "123456", department: "Finance"},
{id: 4, name: "four", email: "4@test.com", password: "123456", department: "Marketing"},
{id: 5, name: "five", email: "5@test.com", password: "123456", department: "Marketing"},
{id: 6, name: "six", email: "6@test.com", password: "123456", department: "Marketing"},
{id: 7, name: "seven", email: "7@test.com", password: "123456", department: "Service"},
{id: 8, name: "eight", email: "8@test.com", password: "123456", department: "Service"},
{id: 9, name: "nine", email: "9@test.com", password: "123456", department: "Service"}
];
那么我有一个对象
data = {name: "conrad", email: "conrad@test.com", password: "123456", department: "Admin", id: 1}
如何确定列表中是否存在数据 我试过以下给出未定义的答案
signUp(data) {
console.log(data);
console.log(this.list.find(l => l === data));
}
也尝试了一些,包括。
【问题讨论】:
-
你不能使用
===比较对象 -
使用 loadash
_.isEqual(object, other) -
This 解释了为什么它不起作用,以及如何解决这个问题:
标签: javascript arrays angular object