对象解构取值
let {a, b, c} = {a:1, b:2, c:3};console.log(a,b,c);
合并数组【去重】
let a = [1, 2, 3],b = [3, 4],c = [...new Set(a), ...new Set(b)];console.log(c);
对象合并
let o1 = {a:1},o2 = {b:2},o = {...o1, ...o2};console.log(o);
获取属性值
let obj = {a:1},a = obj?.a,//等价于 obj&&obj.ab =obj?.b;//等价于 obj&&obj.bconsole.log(a);console.log(b);
输入框非空判断
if((value??'')!= ''){/*todo...*/}/*等价于*/if(value != undefined && value != null && value != ''){/*todo...*/}
对象多层嵌套,获取最底层val
const input = {a: {x: {b: {cc: 'test1'}},y: {dd: 'test2'},z: 'ok'}};const output = str => {const index = str.split('.');return index.reduce((prev, cur) => {return prev[cur]},input)};output('a.x.b.cc');//test1
数组分组
function group(arr, step) {return arr.reduce((x, y) => {return x[x.length - 1].push(y) === step ? (idx !== arr.length-1 ? [...x, []] : [...x]) : [...x]}, [[]])}console.log(group([1,2,3,4,5,6,7], 4))
