0

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?

DCR
  • 14,737
  • 12
  • 52
  • 115

0 Answers0