[Vuejs]-Trying to fetch the matching data from the array of objects by comparing array of objects

1👍

If the length of array A and array B is the same and the elements to be compared are at the same index within those arrays it’s pretty easy and a simple for-loop will do.
The elments itself are objects in both arrays, so you can simply use the dot notation to access the objects properties e.g. arrayA[0].AccountNum would return the AccountNum of array A’s first element.

Here’s an example:

let arrayA = [{
    "invoice": "500",
    "number": "2"
}, {
    "invoice": "500",
    "number": "1"
}];

let arrayB = [{
        "iNumber": "0312",
        "parentInvcNum": null,
        "billDate": "2023-03-12T00:00:00Z",
        "billingAddress": "KING NB",
        "AccountNum": "50078887",
        "status": "L",
        "StatusCode": "2"
    },
    {
        "iNumber": "0332",
        "parentInvcNum": null,
        "billDate": "2023-03-12T00:00:00Z",
        "billingAddress": "KING MB",
        "AccountNum": "50073287",
        "status": "K",
        "StatusCode": "1"
    }
];

for (let a = 0; a < arrayA.length; a++) {
    console.log(arrayA[a].invoice == arrayB[a].AccountNum, arrayA[a].number == arrayB[a].StatusCode);
}

Leave a comment