javascript - 有没有办法将字符串数组用作具有解构赋值的变量名?(Javascript)
问题描述
让我们记住,通常的解构赋值如何与数组一起工作:
const numbers = ['one', 'two', 'three'];
[one, two, three] = numbers;
console.log(`${one} ${two} ${three}`);
但是,如果我们有很长的数据数组,例如有 20 个项目怎么办?如上例所示,手动列出它们似乎并不好。有没有办法通过解构赋值提取字符串数组并将字符串用作值?
伪代码:
let numbers = ['one', 'two', 'three'];
[...numbers] = numbers;
预期结果:
console.log(one); // 'one'
console.log(two); // 'two'
console.log(three); // 'three'
我觉得它不是为这种情况设计的,对吗?
解决方案
推荐阅读
- javascript - 三.js项目-添加导入导致blanc页面
- javascript - 处理 TypeError 的可能方法是无法读取 null 的属性“某物”?
- hyperledger-fabric - hyperledger Fabric 和 hyperledger Besu 的区别
- excel - 加密的 Excel 工作簿作为程序的数据库
- javascript - 如何设计一个长时间运行的javascript函数以避免浏览器警告“无响应脚本”
- centos7 - fpm / RPM:如何使用 fpm 创建多个较小的 rpm 文件,使用目录作为源?
- python - 无法与 pip 一起使用。错误:无法执行“--user”安装
- node.js - 全局模块 MODULE_NOT_FOUND 如果从 pm2 开始
- python - 如何在不使用循环或任何关键字的情况下打印字典的“键”?
- java - 安装的构建工具修订版 30.0.3 已损坏