I have the following two functions:
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]
could someone explain what [val] is in the second function? Why are the [] needed?