根据值从多维数组中删除元素
本文关键字:数组 删除 元素 | 更新日期: 2023-09-27 18:16:16
我试图删除基于StockNo值的多维数组中的元素。
我的数组是这样的:
Array[2]
0: Object
StockNo: "1"
InvoiceNo: "1234"
MaterialName: "MaterialName1"
PONo: "1234"
PRNo: "2124"
Project: "ProjectName"
Qty: "1"
Remarks: "Test"
Supplier: "SupplierName"
TotalAmount: "23"
Type: "2"
Unit: "23"
1: Object
StockNo: "2"
InvoiceNo: "1234"
MaterialName: "MaterialName2"
PONo: "1234"
PRNo: "2124"
Project: "ProjectName2"
Qty: "1"
Remarks: "Test"
Supplier: "SupplierName"
TotalAmount: "23"
Type: "2"
Unit: "23"
逻辑是:
var StockNo = 1;
while(//find StockNo in the Multi-dimentional array ){
if(//StockNo found){
//remove element
}
}
如何在jquery中做到这一点?
KYLE GWAPO
尝试使用数组过滤器:
var arrayOrig = [{ StockNo: "1",
InvoiceNo: "1234",
MaterialName: "MaterialName1",
PONo: "1234",
PRNo: "2124",
Project: "ProjectName",
Qty: "1",
Remarks: "Test",
Supplier: "SupplierName",
TotalAmount: "23",
Type: "2",
Unit: "23"},
{StockNo: "2",
InvoiceNo: "1234",
MaterialName: "MaterialName2",
PONo: "1234",
PRNo: "2124",
Project: "ProjectName2",
Qty: "1",
Remarks: "Test",
Supplier: "SupplierName",
TotalAmount: "23",
Type: "2",
Unit: "23"}]
console.log(arrayOrig);
var filter_array = arrayOrig
.filter(function (el) {
alert(el.StockNo);
return el.StockNo !== "1";
});
console.log(filter_array);
KYLE GWAPO PERO JOKE RA