I have two arrays. Here's the first:
$scope.selection = {
"carrots",
"celery",
"corn",
"apples",
"bananas"
};
Here's the second:
$scope.shipment = [{
"id": "0",
"name": "vegetables",
"manifest": [{"carrots", "celery", "corn"}]
}, {
"id": "1",
"name": "produce",
"manifest": [{"apples", "carrots", "bananas"}]
}];
I'd like to be able to see if a match exists in the second array as I iterate through the first. So far, I can use jQuery inArrayto match an indexed item in the second array:
if ($.inArray($scope.shipment.manifest[0], $scope.selection) < 0) { console.log($scope.shipment.id) };
// for "carrots"
=> "0"
But since "carrots" is in two index positions in the shipment array, the above will only return the first shipment id.
How can I get both shipments?