为什么当运行地图条目时,解构是由 [] 而不是 {}

问题描述

假设我有以下地图

const question = new Map([
  ['question','What is the best programming language in the world?'],[1,'C'],[2,'Java'],[3,'JavaScript'],['correct',3],[true,'Correct ?'],[false,'Try again!'],]);

当我想遍历我正在写的所有内容时:

for (const [key,value] of question) {
  if (typeof key === 'number') console.log(`Answer ${key}: ${value}`);

我的问题是为什么我要写 [key,value] 而不是 {key,value} 因为所有条目都是一个带有键、值的对象。当我打印到控制台 **console.log(question.entries()) 时,我看到所有条目看起来像:{key: 1,value:"c"} 而不是 [1,"c"]。那么为什么解构不是对象解构而是数组解构?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)