Answers for "js find element in array by property"

4

js get array item by property

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"}
Posted by: Guest on October-08-2020
1

javascript find object in array by property value

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']
Posted by: Guest on December-11-2020
0

js find element in array by property

var result = jsObjects.find(obj => {
  return obj.b === 6
})
Posted by: Guest on May-25-2020
0

find object in array by property javascript

// Find an object with a given property in an array
const desiredObject = myArray.find(element => element.prop === desiredValue);
Posted by: Guest on November-20-2020
0

search array for property js

filter()
Posted by: Guest on October-24-2020

Code answers related to "js find element in array by property"

Code answers related to "TypeScript"

Browse Popular Code Answers by Language