Lets have an example JS object (aka "associative array"):
var zoo = {
monkey: { legs: 4, color: "black" },
fish: { legs: 0, color: "yellow" },
turtle: { legs: 4, color: "green" },
emu: { legs: 2, color: "gray" },
};
Now I want to retrieve a nested object (aka "subarray") of aquatic animals. Is there a standard JS/jQuery construct or function to filter object properties by array ("index an array by array"), i.e. something like:
var aquatic = zoo["fish", "turtle"];
The result should obviously be { { legs: 0, color: "yellow" }, { legs: 4, color: "green" } }.
Or is a for loop the simplest solution here?
for..into loop over properties of an objectvar aquatic = ["fish", "turtle"].map(key => zoo[key])