I am attempting to search through an array to find a query string within a JSON object. The results are filtered and displayed as an array, but currently only the name field is being returned, not the number field.
computed: {
search: function () {
let self = this
let filtered = []
filtered = self.jcontacts.filter(function(contact){
return contact.firstname.toLowerCase().indexOf(self.query.toLowerCase())>=0 ||
contact.lastname.toLowerCase().indexOf(self.query.toLowerCase())>=0;
//contact.email.toLowerCase().indexOf(self.query.toLowerCase()) >=0 || - Removed for better performance
//contact.phonenumber.toLowerCase().indexOf(self.query.toLowerCase()) >=0; - Removed for better performance
}
);
return this.contacts = filtered
}
},
}
The issue with the number not appearing in the filtered method is due to how it's structured. Here is an example of the JSON data:
[ { "id": 1, "phoneNumber": [ "3908902" ], "email": [ "[email protected]" ], "firstname": "Jamie", "lastname": "Fox" }]