I encountered an issue while coding this script in Nuxtjs. When I try to filter a list of users based on a keyword search, it throws an error.
<script>
export default {
computed: {
user() {
let user = [{name_en: 'Jack'},{name_en: 'Joe'}]
return user.filter(item => item.name_en.toLowerCase().includes(keywordSearch))
}
}
}
</script>
The error message states Cannot read property 'toLowerCase' of undefined in javascript. However, when I change the filter condition to check for 'Jack' specifically, there is no error.
return user.filter(item => item.name_en === 'Jack')
This inconsistency is confusing me. How can I resolve this issue?