In my Vue Js 2.0 application, I am working on filtering elements in an array format. Here is the code snippet:
const search = this.search_by_name.toLowerCase()
const searchContact = this.search_by_contact.toLowerCase()
return this.meetings
.map(i => ({
id: i.interaction.id,
client_name: i.client.name,
contactName: i.contacts_association,
}))
.filter((item) =>
item.client_name.toLowerCase().includes(search)
)
I am facing an issue with filtering based on
item.contactName.first_name.toLowerCase().includes(searchContact)
. The error being thrown is:
TypeError: item.contactName.toLowerCase is not a function
The structure of my contacts_association
data is as follows:
"contacts_association":[
{
"id":431,
"first_name":"Nikunj",
"last_name":"Doshi",
"address":"602-603, 6th Floor, Dalamal House,Nariman Point",
"city":"Mumbai",
"state":"Maharashtra",
"country":"India",
"pivot":
{
"interaction_id":139,
"contact_id":431,
"company_id":160,
"created_at":"2017-09-23 16:42:56",
"updated_at":"2017-09-23 16:42:56"
},
"company":[
{
"id":160,
"name":"Bay Capital Investment Managers Pvt Ltd",
"address":"602-603, 6th Floor, Dalamal House,Nariman Point",
"city":"Mumbai",
"state":"Maharashtra",
"country":"India",
"type":"Investor",
"sub_type":"FII",
"is_client":0,
}
]
},
{
"id":431,
"first_name":"Vikash",
"last_name":"Kumar",
"address":"602-603, 6th Floor, Dalamal House,Nariman Point",
"city":"Mumbai",
"state":"Maharashtra",
"country":"India",
"pivot":
{
"interaction_id":139,
"contact_id":431,
"company_id":160,
"created_at":"2017-09-23 16:42:56",
"updated_at":"2017-09-23 16:42:56"
},
"company":[
{
"id":160,
"name":"Investment Managers Pvt Ltd",
"address":"Nariman Point",
"city":"Mumbai",
"state":"Maharashtra",
"country":"India",
"type":"Investor",
"sub_type":"FII",
"is_client":0,
}
]
}
]
I need help in filtering based on both first_name
and last_name
.