0: {id: 1553825061863, name: "Thai Milk Tea", qty: "1", total_amount: 9500, toppings: 500, …}
1: {id: 1553825061863, name: "Thai Milk Tea", qty: "1", total_amount: 9500, toppings: 500, …}
2: {id: 1553825061863, name: "Thai Milk Tea", qty: "1", total_amount: 9500, toppings: 500, …}
我想删除数组中的
0:{}
数组。我该如何删除?以及如何找到第一项的价值? 最佳答案
从您的问题中我了解到,您必须像下面这样从Array1中删除Array2,
Array1 = 0: {id: 1553825061863, name: "Thai Milk Tea", qty: "1", total_amount: 9500, toppings: 500, …}
1: {id: 1553825061863, name: "Thai Milk Tea", qty: "1", total_amount: 9500, toppings: 500, …}
2: {id: 1553825061863, name: "Thai Milk Tea", qty: "1", total_amount: 9500, toppings: 500, …}
Array2 = 0: {id: 1553825061863, name: "Thai Milk Tea", qty: "1", total_amount: 9500, toppings: 500, …}
如果是这样,请使用过滤器功能尝试以下操作。
var data = Array1;
var selectedRows = Array2;
var unSelectedRows = [];
var unSelectedRows = data.filter( function( el ) {
return !selectedRows.includes( el );
} );
您可以在unSelectedRows数组中获得第1个和第2个元素。