There is a data set of this type.

{ "id": "448", "text": "Инструкции вида 123", "childs": { "168": { "id": "168", "name": "Инструкция к товару А168", "link": "/download/168.zip" }, "1689": { "id": "1689", "name": "Инструкция к товару Б1689", "link": "/download/1689.zip" }, "390": { "id": "390", "name": "Инструкция к товару В390", "link": "/download/390.zip" } } } 

It is necessary to implement a search so that when entering, for example, А168 , data of the А168 returned:

 { "id": "448", "text": "Инструкции вида 123", "childs": { "168": { "id": "168", "name": "Инструкция к товару А168", "link": "/download/168.zip" } } } 

An example of how I tried to implement this without success:

 computed: { postList_n() { return this.postList.filter(item => { return item.childs.name.toLowerCase().includes(this.search.toLowerCase()) }) } }, 
  • 2
    Is there an example of your implementation? What did you do for hip-hop in your time? - Yegor Zholnin
  • @ YegorZholnin added an example - alexsoin
  • @alexsoin you are in the right direction, only you have an object, and the filter method is applied to an array and returns an array ... - Doigrales
  • @Doigrales can tell, for objects what then is better to use instead of filter ? - alexsoin

1 answer 1

 postList_n() { let obj = this.postList.childs; let newArray = []; const serach = this.search.toLowerCase(); for (key in obj) { el = obj[key] if (el.name.toLowerCase().indexOf(serach) != -1) newArray.push(el); } return newArray; } 

Here is an example on codepen