I am really surprised I haven\'t been able to find anything related to my question. I am looking for a fast way to filter my array of objects based on a user text input.
You could use Object.keys()
and some()
instead.
let data = [{
"id": 1,
"first_name": "Jean",
"last_name": "Owens",
"email": "jowens0@google.ru",
"gender": "Female"
}, {
"id": 2,
"first_name": "Marie",
"last_name": "Morris",
"email": "mmorris1@engadget.com",
"gender": "Female"
}, {
"id": 3,
"first_name": "Larry",
"last_name": "Wallace",
"email": "lwallace2@example.com",
"gender": "Male"
}];
var result = data.filter(function(o) {
return Object.keys(o).some(function(k) {
return o[k].toString().toLowerCase().indexOf('s') != -1;
})
})
console.log(result)