js理解箭头符号三元运算符

时间:2018-05-10 20:38:30

标签: javascript ternary-operator arrow-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]

有人可以解释第二个函数中的[val]是什么吗?为什么需要[]?

0 个答案:

没有答案