I am trying to filter below array of objects against search variable which is a string. So, user can search based on title, year or name of people
array = [{
"title": "Test",
"year": 2018,
"people": [
{
"name": "person1"
},
{
"name": "person2"
}],
},
{
"title": "Test2",
"year": 2018,
"people": [
{
"name": "person3"
},
{
"name": "person4"
},
{
"name": "person5"
}],
},...]
I have written the below function which works fine for title and year but I could not figure out how to search the people array inside the function. I know how to do it without ES6 but I prefer ES6 which is still confusing to me:
filteredArray() {
let search = this.search.toLowerCase();
return this.array.filter(function (item) {
return Object.values(item).some(val =>
String(val).toLowerCase().includes(search));
})
},
this.search is the v-model that holds the value user types in.
Here is the Codepen
I appreciate your help :)