user3378165
user3378165

Reputation: 6916

Iterate through object array exclude one key

I have this function that iterates through an object array keys and call a function for each one of the keys. What would we the easiest way to skip / ignore two of the keys?

Object.entries(newContactInfo).map(([key, value]) => {
  const errorItem = `${key}Error`;
  this.changeErrorValue(!value, errorItem);
});

Upvotes: 2

Views: 2180

Answers (1)

Code Maniac
Code Maniac

Reputation: 37745

You can use forEach with if else

Object.entries(newContactInfo).forEach(([key, value]) => {
  const errorItem = `${key}Error`;
  if(condition as per your requirement here ){
    this.changeErrorValue(!value, errorItem);    
  }
});

On side note : map is supposed to use when you manipulate all the values in some manner and you want them back. for simple iteration use for or forEach

Upvotes: 2

Related Questions