[Vuejs]-Advanced search with computed property vuejs

0👍

someArray.toString returns array items separated by comma , so try to replace that comma by space as follow :

template.keywordArray.toString().replace(","," ").toLowerCase().includes(this.searchQuery.toLowerCase());

if the searched words are not in order you could use the following approach:

this.searchQuery.toLowerCase().split(' ').every(val => {
  return template.keywordArray.toString().toLowerCase().split(',').filter(item => {
    return item.includes(val)
  }).length !== 0;
})
/***OR directly search in keywordArray***/
this.searchQuery.toLowerCase().split(' ').every(val => {
  return template.keywordArray.filter(item => {
    return item.includes(val)
  }).length !== 0;
})

A sample code :

var items = ["aaa", "bbb", "ccc", "ddd"]
var s = "aaa bb"
var f = s.split(" ").every(st => {
  return items.filter(item => {
    return item.includes(st)
  }).length !== 0;
})
console.log(f)

Leave a comment