arrays - 如何在javascript中复制数组值
问题描述
输入
var key=[ 'id', 'name', 'health', 'status', 'environment', 'serviceType' ]
我期待以下输出(值的重复)
['id','name','health','status','environment','serviceType','id','name','health','status','environment','serviceType']
解决方案
使用spread-operator
:
const key = [ 'id', 'name', 'health', 'status', 'environment', 'serviceType' ]
const res = [...key, ...key];
console.log(res);
使用Array#concat
:
const key = [ 'id', 'name', 'health', 'status', 'environment', 'serviceType' ]
const res = key.concat(key);
console.log(res);
推荐阅读
- spring - Redis Sentinel:可以连接到sentinel,但是master-1;好像没有监控
- reactjs - 如何将状态传递给 firebaseConnect 中的 doc 属性
- c# - 是否可以在不修改基类的情况下从派生类中更改基类方法中使用的类型?
- c# - 如何按聚合分组?
- file - 如何将 iTextSharp.text.Image 保存到文件
- babeljs - babel 无法解析表达式 `{ display: 'block',}`
- authentication - 在 ASP 中分离前端和后端服务身份验证。网络核心
- php - php脚本更新数据库以匹配数量,而不是添加到它
- button - 我如何防止在表单提交 Angular 7 上重新加载页面
- node.js - 如何使用 officegen 和 Angular 应用程序生成 Word 文档?