const jsObjects = [
{id: 1, displayName: "First"},
{id: 2, displayName: "Second"},
{id: 3, displayName: "Third"},
{id: 4, displayName: "Fourth"}
]
// You can use the arrow function expression:
var result = jsObjects.find(obj => {
// Returns the object where
// the given property has some value
return obj.id === 1
})
console.log(result)
// Output: {id: 1, displayName: "First"}
// To find a specific object in an array of objects
myObj = myArrayOfObjects.find(obj => obj.prop === 'something');
// Find an object with a given property in an array
const desiredObject = myArray.find(element => element.prop === desiredValue);
const fruits = ['apple', 'banana', 'grapes', 'mango', 'orange'];
const filterItems = (needle, heystack) => {
let query = needle.toLowerCase();
return heystack.filter(item => item.toLowerCase().indexOf(query) >= 0);
}
console.log(filterItems('ap', fruits)); // ['apple', 'grapes']
console.log(filterItems('ang', fruits)); // ['mango', 'orange']
function variableName(value) {
for (var i=0, iLen=array.length; i<iLen; i++){
if (array[i].property == value) return array[i]
}
};