JavaScript Challenge 71

황상진·2022년 9월 3일
0

JS-Challenge

목록 보기
4/4

Filtering Array of objects

https://www.instagram.com/p/CiAdrQtP6cX/

const users = [
  {firstName: "Fabio", lastName:"Bergmann"},
  {firstName: "John", lastName:"Robert"},
  {firstName: "John", lastName:"Doe"},
  {firstName: "Albert", lastName:"Carter"},
]

console.log(filteredItems(users, "fa"));
console.log(filteredItems(users, "be"));
console.log(filteredItems(users, "js"))


function filteredItems(arr, searchTerm){
  let answer = [];

  searchTerm = searchTerm.toLowerCase();
  arr.map(e => {
    const firstN = e.firstName.toLowerCase();
    const lastN = e.lastName.toLowerCase();

    if(firstN.includes(searchTerm) || lastN.includes(searchTerm)){
      answer.push(e)
    }
  })
  return answer;
}
profile
Web FrontEnd Developer

0개의 댓글