ES6箭头功能正常JS转换

时间:2018-01-30 08:55:26

标签: javascript ecmascript-6 arrow-functions

我很难在普通的JS语法中编写以下内容,因为IE不支持ES6 JavaScript。

更新问题。

我的输入如下。

var onlyData =  [
["Individual Id","Individual Last Name","Individual First Name","Individual Middle Name"],
["1268933","mrs","jeanine","marie"],
["1268934","mr","jasmine","curry"]
] 
 var headers = onlyData.shift();
 var outputJSONObj = onlyData.map(a => a.reduce((r, v, i) => (r[headers[i]] = v, r), {}));

我的变量outputJSONObj的输出如下。

[
{
"Individual Id": "1268933",
"Individual Last Name": "mrs",
"Individual First Name": "jeanine",
"Individual Middle Name": "marie"
},
{
"Individual Id": "1268934",
"Individual Last Name": "miss",
"Individual First Name": "jasmine",
"Individual Middle Name": "curry"
}
]

请使用函数以正常语法重写。

2 个答案:

答案 0 :(得分:1)

var onlyData = [
  ["Individual Id", "Individual Last Name", "Individual First Name", "Individual Middle Name"],
  ["1268933", "mrs", "jeanine", "marie"],
  ["1268934", "mr", "jasmine", "curry"]
]

var headers = onlyData[0] || undefined;`

var outputJSONObj = onlyData.map(function (a) { return a.reduce(function (r, v, i) { return (r[headers[i]] = v, r) }, {}) });`

答案 1 :(得分:1)

你去吧

typeof(Access).GetModelMetadata()