猿问

数组怎么返回符合条件的元素

比如
["1","","","",""]
我想得到数组里不为""的元素,即返回结果为"1"

慕后森
浏览 1422回答 4
4回答

婷婷同学_

var items = ["1","","","",""]var filtered_items = items.filter(item => item !== '')console.log(filtered_items)

aluckdog

["1","","","",""].filter(v=>v!="")

一只甜甜圈

filter了解一下。
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答