首页 > 解决方案 > Angular如何用键从数组拼接?

问题描述

我有这个问题我以这种方式将数据推送到数组中。

this.checkedList.push({"customer_id" : option.id });

我怎样才能再次拼接这个值?没有钥匙,这是有效的:

this.checkedList.splice(option.id,1);

标签: arraysangularsplice

解决方案


您可以使用数组上的findIndex原型方法来查找您要查找的元素的键,例如

let index = this.checkedList.findIndex((element) => element["customer_id"] == option.id);

然后像往常一样拼接数组。

this.checkedList.splice(index, 1);

推荐阅读