javascript - js理解箭头符号三元运算符
问题描述
我有以下两个功能:
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] 是什么吗?为什么需要 []?
解决方案
推荐阅读
- html - 我应该如何在侧边栏菜单下方放置图像
- apache - nginx 作为 Apache 前端:如何重定向一些图像文件?
- javascript - 导航栏在 activeState 期间不显示 css
- javascript - PHP中的简单编码和Javascipt中的解码
- django - 参照父模型的表创建Django抽象子模型
- python - 为什么需要将类分配给变量才能使用它?不同于功能
- python - Discord.py:如何查看成员是否具有在使用 cmd 时必须 ping 自己的角色
- import - 我是否通过“进口”节省费用?
- flutter - 如何在windows的flutter中为ios构建版本?
- java - 从 Java 文件中读取 PEM 编码的加密私钥