JS filter

109 阅读1分钟

前言: filter用于对数组进行过滤,不会改变原始数组

语法: Array.filter(function(currentValue, indedx, arr), thisValue)

业务场景: 返回数组中所有publicUrl不为null的元素。

const newArray = array.filter(item => item.publicUrl !== null);