Attempting to correlate two sets of array values. One set is sourced from a local JSON file, while the other set comes from a backend service.
Data from Local JSON:
var localJsonArray = {
"records": {
"cat1": [{
"id": 1234,
"label": "a"
}, {
"id": 2345,
"label": "b"
}],
"cat2": {
"id": 12345,
"label": "c"
}
}
}
Data from Backend Array:
The data retrieved from the backend is stored as follows:
var backendArray =[0: "1234", 1: "3456", 2:"4567"];
JS Logic:
$.each( localJsonArray, function( key, value ) {
var index = $.inArray( value, backendArray );
if( index != -1 ) {
console.log( index );
}
});
How can I map the id of the local JSON to the id of the backend JSON? If a match is found, the loop should break; otherwise, it should continue searching for a matching value.