javascript 数组用[]不可以声明关联数组,但是可以存放关联数组?

var a = ["name","age","sex"]; 

var b = ["lisi",18,"man"]; 

var arr = new Array(); 

for(var i = 0; i < a.length; i++) { 

arr[a[i]] = b[i]; 

console.log(arr);


皈依舞
浏览 630回答 1
1回答

FFIVE

可以试试使用Map。。var&nbsp;myMap&nbsp;=&nbsp;new&nbsp;Map(); myMap.set("name",&nbsp;"lisi"); myMap.set("age",&nbsp;18); myMap.set("sex",&nbsp;"man");for&nbsp;(var&nbsp;[key,&nbsp;value]&nbsp;of&nbsp;myMap)&nbsp;{ &nbsp;&nbsp;console.log(key&nbsp;+&nbsp;"&nbsp;=&nbsp;"&nbsp;+&nbsp;value); }
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript