Array自带方法的实现
Array.flat
const array1 = [1, 2, 3, 4, [5, 6], [7, [8, 9]]];
function flat(list) {
return list.reduce((pre, next) => pre.concat( Array.isArray(next) ? flat(next) : next ),[])
}
功能/算法
将下划线转为驼峰写法:str_demo => strDemo
let str = 'str_demo'
str = str.replace(/_[a-zA-Z]/g, (par) => { return par[1].toLocaleUpperCase() })
标签:pre,flat,自定义,next,str,Array,方法
From: https://www.cnblogs.com/my-wl/p/17171788.html