Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/398.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Javascript将列表列表转换为字典列表_Javascript - Fatal编程技术网

使用Javascript将列表列表转换为字典列表

使用Javascript将列表列表转换为字典列表,javascript,Javascript,是否有一种内置方式,使用javascript将列表列表转换为字典列表 之前 [ [ "x", "y", "z", "total_count", "total_wins" ], [ 25.18, 24.0, 27520.0, 16, 6, ], [ 25.899, 24.0, 27509

是否有一种内置方式,使用javascript将列表列表转换为字典列表

之前

[
   [
      "x", 
      "y", 
      "z",  
      "total_count", 
      "total_wins"
   ], 
   [
      25.18, 
      24.0, 
      27520.0, 
      16, 
      6, 
   ], 
   [
      25.899, 
      24.0, 
      27509.0, 
      336, 
      8
   ], 
   [
      26.353, 
      26.0, 
      27256.0, 
      240.0, 
      15 
   ], 
   [
      119.0, 
      5.0, 
      6.0, 
      72, 
      0
   ]
]
之后

[
   {
      "x": 25.18, 
      "y": 24.0, 
      "z": 27520.0, 
      "total_count": 16, 
      "total_wins": 6, 
   }, 
   {
      "x": 25.899, 
      "y": 24.0, 
      "z": 27509.0, 
      "total_count": 336, 
      "total_wins": 8
   }, 
   {
      "x": 26.353, 
      "y": 26.0, 
      "z": 27256.0, 
      "total_count": 240.0, 
      "total_wins": 15 
   }, 
   {
      "x": 119.0, 
      "y": 5.0, 
      "z": 6.0, 
      "total_count": 72, 
      "total_wins": 0
   }
]

也许不是内置的,但有一种方法

const input=[[“x”、“y”、“z”、“总计数”、“总赢数”]、[25.18、24.0、27520.0、16、6、]、[25.899、24.0、27509.0、336、8]、[26.353、26.0、27256.0、240.0、15]、[119.0、5.0、6.0、72、0];
const keys=input.shift();
log(input.map(value=>Object.fromEntries)(key.map((key,idx)=>[
钥匙
值[idx]

]))));可能不是内置的,但有一种方法

const input=[[“x”、“y”、“z”、“总计数”、“总赢数”]、[25.18、24.0、27520.0、16、6、]、[25.899、24.0、27509.0、336、8]、[26.353、26.0、27256.0、240.0、15]、[119.0、5.0、6.0、72、0];
const keys=input.shift();
log(input.map(value=>Object.fromEntries)(key.map((key,idx)=>[
钥匙
值[idx]

]))));您可以使用rest操作符、映射和对象。fromEntries

let data=[“x”、“y”、“z”、“total_count”、“total_wins”]、[25.18,24.0,27520.0,16,6,6]、[25.899,24.0,27509.0,336,8]、[26.353,26.0,27256.0,240.0,15]、[119.0,5.0,6.0,72,0];
让[keys,…rest]=数据
让final=rest.map(inp=>Object.fromEntries(inp.map((值,索引)=>[keys[index],value]))

console.log(最终版)
您可以使用rest操作符、映射和对象。fromEntries

let data=[“x”、“y”、“z”、“total_count”、“total_wins”]、[25.18,24.0,27520.0,16,6,6]、[25.899,24.0,27509.0,336,8]、[26.353,26.0,27256.0,240.0,15]、[119.0,5.0,6.0,72,0];
让[keys,…rest]=数据
让final=rest.map(inp=>Object.fromEntries(inp.map((值,索引)=>[keys[index],value]))

console.log(final)
如果您向我们展示了您尝试的内容以及您遇到的问题,这将非常有帮助。如果您向我们展示了您尝试的内容以及您遇到的问题,这将非常有帮助。