1、当表格的列过多,需要横向滚动时需要设置scroll.x,scroll.x 是所有表头的固定宽度累加总和。(antd table)
let columns = [{width:100, ...},{width: 200, ...}]
let scroll = {x: columns.reduce((x, item) => x+item.width, 0)}
console.log(scroll.x) // 300
2、当需要把一个列表的内容组合成一个对象时
let arr = [{key: "code", value: "编码"},{key: "name",value: "名称"}];
let obj = arr.reduce(o, item => {
o[item.key] = item.value
return o
}, {})
console.log(obj) // {code: "编码", name: "名称"}
3、场景arr = [a,b,c], a,b,c都是函数,d=4为参数,得出a(b(c(d)))的结果
let a = (arg) => {return arg+1}
let b = (arg) => {return arg+2}
let c = (arg) => {return arg+3}
let result = arr.reverse().reduce((arg,item) => item(arg),d)
console.log(result) // 10
网友评论