Filter
modern filtering an array
by David McClelland
HTML
<div id="sandbox"></div>
CSS
.box {
height: 40px;
width: 40px;
background-color: yellow;
z-index: 1;
margin: 10px;
}
#sandbox {
background-color: black;
width: 300px;
height: 200px;
display: flex;
}
JavaScript
const aptData = [
{
"petName": "Pepe",
"ownerName":"Reggie",
"aptNotes":"Ask about birthday"
},
{
"petName": "Rio",
"ownerName":"Mary",
"aptNotes":"Ask for insurance update"
}
];
const searchText = 'ask';
const dataFilter = item =>
item.aptNotes.toLowerCase()
.match(searchText.toLowerCase());
var displayData = aptData.filter(dataFilter);
console.log(displayData);