Melodia
4 months ago
355
8
Vue

Filter through array of objects not working

Posted 4 months ago by Melodia

I have an input field in my template that looks like this:

    <input type="text" v-model="search" @keydown="inputChanged" />

Inside my data object I have a list of users:

users: [
  { id: 1, text: "Learn JavaScript", done: false },
  { id: 2, text: "Learn", done: false },
  { id: 3, text: "Play around in JSFiddle", done: true },
  { id: 4, text: "Build something awesome", done: true }
],

How can I return objects based on what the words that a user types when searching for user through text?

My inputChanged method looks like this:

 inputChanged(){
  var filtered = this.users.filter(function (user) {
    return user.text.match(this.search)
  });

If I console log the filtered variable and type any letter, it logs the users' array, which is incorrect.

Please sign in or create an account to participate in this conversation.