首页 新闻 会员 周边 捐助

Javascript代码的小小疑问11.16——Array.from()

0
[已解决问题] 解决于 2017-11-20 10:07
 let obj = ["x","y","z"];
 let objTmp = {};
  Array.from(obj,(o)=>{
    console.log(o+1);
});   //x1,y1,z1

我想得到如下形式:

{x1:'', y1:"",z1:''}, 但不行,How?

 

 let obj = ["x","y","z"];
 let objTmp = {};
  Array.from(obj,(o)=>{
    Object.assign(objTmp, o+1);
});
console.log( objTmp);   //{"0":z, "1":1}

How?

Coca-code的主页 Coca-code | 初学一级 | 园豆:10
提问于:2017-11-16 09:41
< >
分享
最佳答案
0

```

let obj = ["x","y","z"];
let objTmp = {};
Array.from(obj,(o)=>{
objTmp[ o+"1" ] = "";
});
console.log( objTmp);  // {x1:'', y1:"",z1:''}

 

```

奖励园豆:5
若水若鱼 | 菜鸟二级 |园豆:206 | 2017-11-16 14:07

Thank you. 对象的key是自增长的。

Coca-code | 园豆:10 (初学一级) | 2017-11-20 10:08
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册