I have an array of javascript objects, each with three fields, like this:
var people = [
{first: "john", middle: "james", last: "doe"},
{first: "jane", middle: "kate", last: "smith"},
...
{first: "kathy", middle: "rose", last: "green"},
];
I want to be able to query this array based on any of the fields, and get back the object which matches. For instance I want to be able to call something like people.getByMiddle("kate")
and get back {first: "jane", middle: "kate", last: "smith"}
Is there a data structure that makes associating these things in this way easier, or should I just write three separate functions each of which iterates over my data and searches for a match? I don't want anything that relies on the ordering of arrays.