我有以下两个功能:
const sections = Object.keys(this.state.obj).map(key => {console.log(key,'x')
return({
key,
title: key,
// turn array of values into array of objects in the shape {key, value}
data: toArray(this.state.obj[key]).map(toObject),
})})
const toArray = val => val instanceof Array ? val : [val]
有人可以解释第二个函数中的[val]是什么吗?为什么需要[]?