赞誉中具有复杂条件的javascript过滤器

赞誉中具有复杂条件的javascript过滤器,javascript,filter,Javascript,Filter,为什么这样做有效: var words = ['spray', 'limit', 'elite', 'exuberant', 'destruction', 'present']; const result = words.filter( word => word.length > 6 ); console.log(result); // expected output: Array ["exuberant", "destruction", "present"] 但在修改这一

为什么这样做有效:

var words = ['spray', 'limit', 'elite', 'exuberant', 'destruction', 'present'];

const result = words.filter(
  word => word.length > 6
);

console.log(result);
// expected output: Array ["exuberant", "destruction", "present"]
但在修改这一部分后,不会:

const result = words.filter(
      word => {
        word.length > 6
      }
    );
请注意,我想将
word.length>6
放在赞誉中,我想实际进行更复杂的中间计算(超过1行)


任何建议,请感谢。

当表达式被括号括起时,您需要使用
return
关键字:

const result = words.filter(
  word => {
    return word.length > 6
  }
);
第一版:

var words=['spray'、'limit'、'elite'、'experiant'、'destruction'、'present'];
const result=words.filter(word=>word.length>6);

console.log(result)
您需要添加
return
关键字在您的工作示例中,您使用单行语法,可以删除括号和return语句