从url拿到的数组参数,变成字符串。。所以得处理下。。
比如现在有一个这样的字符串:
var a = "[1,3,2]"
先转成数组:
let b = [...a] console.log(b) //["[", "1", ",", "3", ",", "2", "]"]
再过滤:
let c = b.reduce((arr, v)=>{ (typeof Number(v)) === ‘number‘ && !isNaN(Number(v)) && arr.push(Number(v)) return arr },[]) console.log(c) // [1, 3, 2]