【发布时间】:2018-05-26 23:08:47
【问题描述】:
storyWords.filter(word => if (unnecessaryWords.includes(word)){
continue;
}
else{
betterWords.push(word);
}) ;
我不断收到错误“Unexpected token if”,我想知道当您使用箭头函数时,if 语句的语法是否与常规函数中的不同。
【问题讨论】:
-
您不能在只允许使用表达式的上下文中使用语句或声明。使用带有
{}的箭头函数,以便您可以在其中放置语句。 -
这不是过滤器的使用方式..应该是
betterWords = storyWords.filter(word => !( unnecessaryWords.includes(word) ));
标签: javascript arrays ecmascript-6