给定数组
名称['a','b','c']
数据[1 , 2 , 3]
我想要结果
[{name: 'a', data: 1}, {name: 'b', data: 2}, {name: 'c', data: 3}]
,
我能做到
let combinedData = [];
for (let i = 0; i < data.length; i++) {
combinedData.push({name: name[i], data: data[i]});
}
但我正在寻找一种优雅的方式,拍摄。 (使用外部库是可以接受的,例如lodash)
答案 0 :(得分:2)
您可以使用Array.map:
let name = ['a','b','c'];
let data = [1,2,3];
let combined = name.map((v, i) => ({name: v, data: data[i]}));
console.log(combined);
&#13;
答案 1 :(得分:1)
一个简单的es6解决方案可能是:
let arr1 = ...;
let arr2 = ...;
let data = arr1.map((item, i) => ({a: item, b: arr2[i]}));
答案 2 :(得分:1)
location = /upload {
auth_request /upload/authenticate;
...
}
location = /upload/authenticate {
internal;
proxy_set_body off;
proxy_pass http://backend;
}