请问这样格式的数组怎么转为对象?数组如下:["38:21","33:12","11:22"]我想把它转为下面这种格式的对象{
38:21, 33:12,
11:22 }弄了好久没弄好,求大神帮忙!!
2 回答
摇曳的蔷薇
TA贡献1793条经验 获得超6个赞
["38:21","33:12","11:22"].map(o=>{ let kv = o.split(":"); return {[kv[0]]:kv[1]} })
回首忆惘然
TA贡献1847条经验 获得超11个赞
var source = ["38:21", "33:12", "11:22"];var target = {};for (var i = 0; i < source.length; i++) { var tmpSplitArray = source[i].split(":"); target[tmpSplitArray[0]] = parseInt(tmpSplitArray[1]); } console.log(target);
添加回答
举报
0/150
提交
取消