Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
519 views
in Technique[技术] by (71.8m points)

.filter(_ => _) js代码这个是什么意思?

.filter(_ => _)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

过滤出 Truthy 元素。

JS 里允许变量名是 _$ 这两个字符开头,所以其实就是:

arr.filter(_ => _);

// 等价于
arr.filter(e => e);

// 等价于
arr.filter(e => !!e);

// 等价于
arr.filter(e => {
  return !!e;
});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...