[Vuejs]-How can search through json data in vue?

0👍

Inside your filter function, first you set new_json = x (which is an object), but then inside the for loop you set new_json to be a match result, which would be an array, and it would not have the members as the original object (x), so it would crash on the next loop.

I’m guessing that what you need is something like this:

return this.myJson.filter((x) => {
    let match = true;
    console.log(x);
    for(let i in this.search){
        console.log(x[i])
        console.log(this.search)
        if(!x[i].toLowerCase().match(this.search[i].toLowerCase())) match = false;
    }
    return match;
});

Leave a comment