자바스크립트 필터

// Filter in Javascript

// Datas
const userDatas = [
  {firstName : "Aboubacar" , lastName : "Barry"},
  {firstName : "Bill" , lastName : "Gates"},
  {firstName : "Amadou" , lastName : "Diakité"}
]

// filter function
const filteredDatas = (datas,props,str)=>{
  if(!props || props === null){
    return null;
  }
    const filter = datas.filter(data=>{
      if(data.[props].startsWith(str)){
        return data
      }
    })
//     global return 
    return (filter.length === 0 ? "Not Founds In Tables" : filter); 
}

// results
filteredDatas(userDatas,"firstName","A") 
// [ {firstName : "Aboubacar" , lastName : "Barry"}, {firstName : "Amadou" , lastName : "Diakité"}]

filteredDatas(userDatas,"","M") 
// null

좋은 웹페이지 즐겨찾기