我试图根据 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中执行此操作?
答案 0 :(得分:1)
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