javascript – .filter is not a function

javascript – .filter is not a function

filter is a method on arrays. Since the code you posted contains an object, youre seeing this error. You may want to apply filter after getting all the values from the object using Object.values, like this:

var users = {
  1: {
    user_id: 1,
    test: ,
    user_name: potato0,
    isok: true
  },

  2: {
    user_id: 2,
    test: ,
    user_name: potato1,
    isok:  true
  },

  3: {
    user_id: 3,
    test: ,
    user_name: potato2,
    isok:  true
  },

  4: {
    user_id: 4,
    test: ,
    user_name: potato3,
    isok: locationd
  }
};

console.log(Object.values(users).filter(user => user.user_id === 1));

javascript – .filter is not a function

Leave a Reply

Your email address will not be published.