如何将数组元素隐藏或添加到对象中。
现在
arr = [
["1/1/2017",113],
["3/11/2017",58],
["3/12/2017",70],
["3/13/2017",76]
]
应该
arr = [
{date:"1/1/2017", count:113},
{date:"3/11/2017", count:58},
{date:"3/12/2017", count:70},
{date:"3/13/2017", count:76}
]
最佳答案
arr.map(function(arr1) {
return {
date : arr1[0],
count : arr1[1]
}
})
关于javascript - 在javascript中将数组转换为具有键和值的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43321751/