从数组中删除特定项目 - 本机反应

Remove the particular item from the array - react native

如果条件匹配,如何从数组循环中删除特定项目?

array.map(item => {
   item.id === companyId ? 
      //how to remove this item from the array??
} : null)

提前致谢

可以使用原生JS.filter方法

const newArray = array.filter(item => item.id !== companyId)

这将return一个没有匹配项的新数组。

您可以使用filter函数:

var data = [{id: 1}, {id: 2}, {id: 3}];

const result = data.filter(val => val.id != 2);

console.log(result);