My question:
I have an array of objects as such
var people = [
{name: 'Dan' , age: '20', favoriteColor : 'blue'},
{name: 'Bob' , age: '35', favoriteColor : 'red' },
{name: 'Frank', age: '22', favoriteColor : 'green'},
{name: 'Ed' , age: '27', favoriteColor : 'yellow'}
]
I need to be able to identify the objects in the array by their name property. [It's important to note that the name property for each object in the array WILL be unique]. However, they are not ordered by any particular pattern. So people[0] may or may not equal the object with a 'name' of 'Dan'.
I want to be able to access the data by organizing it so that
people.Dan
returns the object
{age: '20', favoriteColor: 'blue'}
I feel like this should be relatively simple, but I don't really know the words to describe the issue to be able to find the proper solution.
EDIT: For anyone reading this in the future, I decided to go with Elliot's solution instead of using underscore.js. They both solve the problem, but it ended up being easier just to implement another function.