Find
Search through an array and look for particular element. As soon as item is found, helper will return that value.
Drawback, if we only have two of the same element, it will only find the first one in the array.
//ES5 Solution
var users = [
{name: 'Jill'),
{name: 'Alex'),
{name: 'Bill')
]
var user;
//Need to go through entire length of the array
for (var i = 0; i<products.length; i++){
if(users[i].name === 'Alex') {
user = user[i];
break;//Might fix going through the loop
}
}
//ES6 Solution
users.find(function(user) {
return user.name === 'Alex';
}