s24344,
<!DOCTYPE html>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<style type="text/css">
</style>
</head>
<body>
<ul class="list"></ul>
<script>
function fn(arr, pattern) {
pattern = new RegExp("^(" + pattern.trim().replace(/\s+/g, "|") + ")", "i");
return arr.filter(function(el) {
return Object.values(el).some(function(val) {
return pattern.test(val)
})
})
};
let arr = [
{
id: 1,
firstName: 'John',
lastName: 'Smith'
},
{
id: 2,
firstName: 'Brady',
lastName: 'Dennis'
},
{
id: 3,
firstName: 'Sandoval',
lastName: 'Pratt'
},
{
id: 4,
firstName: 'Davis',
lastName: 'Andrews'
}
]
,
pattern = 'Pratt Sm',
arrFilter = fn(arr, pattern),
html = arrFilter.reduce(function(html, el) {
return html += '<li class="item" ><div>'+el.firstName+' '+ el.lastName+'</div></li>'
},"");
document.querySelector(".list").innerHTML = html;
</script>
</body>
</html>