user6761897
user6761897

Reputation:

Skipping a value in map() in javascript

I'm a rank newcomer to javascript, thus the question, I'm mapping through a dictionary to render a li of elements in React. This is my code,

<SplitButton id={this.state.title} title={this.state.title}>
          {Object.keys(dict).map(key => <MenuItem key={dict[key]} href={`#${dict[key]}`} onSelect={() => this.onTargetSelect(key,dict[key])}>{key}</MenuItem>)}
        </SplitButton>

I want to skip the rendering for a particular value(not key). How can I do this in Javascript.

Upvotes: 0

Views: 520

Answers (1)

Mike Cluck
Mike Cluck

Reputation: 32511

filter it out first.

var obj = {
  a: 1,
  b: 2,
  skip: 3,
  d: 4
};

var result = 
    Object.keys(obj)
      .filter(key => key !== 'skip')
      .map(key => obj[key]);
console.log(result);

Upvotes: 4

Related Questions