1

I'm trying to delete the elements inside a multi-dimensional array based on value which is StockNo.

My array is like this:

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"

The logic is:

var StockNo = 1;
while(//find StockNo in the Multi-dimentional array ){
    if(//StockNo found){
       //remove element
    }
}

How can I do this in jquery?

1 Answer 1

1

KYLE GWAPO

Try to Use array filter :

  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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.