Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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']
Comment

search array for property js

filter()
Comment

PREVIOUS NEXT
Code Example
Javascript :: Authentication handling in javascript 
Javascript :: nodemailer 
Javascript :: hasChildNodes 
Javascript :: vue3 header 
Javascript :: about ajax 
Javascript :: js select all 
Javascript :: redis pub or sub nodejs 
Javascript :: react responsive nav bar 
Javascript :: javascript compare dates 
Javascript :: Use the parseInt Function 
Javascript :: what does return do in javascript 
Javascript :: Movie-app using react 
Javascript :: data types in js 
Javascript :: loading screen fivem js 
Javascript :: type time angular 
Javascript :: web scraping using javascript 
Javascript :: nested callbacks javascript 
Javascript :: update property of object in array javascript 
Javascript :: pass a function as a parameter in other function 
Javascript :: javascript weakmap 
Javascript :: 10 to the power of negative n 
Javascript :: call two functions onpress react native 
Javascript :: javascript strin literal 
Javascript :: web animation api keyframe options 
Javascript :: React closing a dropdown when click outside 
Javascript :: javascript destructuring 
Javascript :: toggle buttons angular styles 
Javascript :: how to make callback function javascript 
Javascript :: find vs filter 
Javascript :: reactjs debounce 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =