我有一个以下数组:
<script type="text/javascript" src="your_js_file.js"></script>
想转换为以下格式(也将日期从20160221更改为2016-02-21)
var array = [
[
'20160221',
'10'
],
[
'20160307',
'20'
]
];
谢谢。
答案 0 :(得分:1)
这是一个示例代码:
var array = [
[
"20160221",
"10"
],
[
"20160307",
"20"
]
];
var newArr = array.map(function(item){
return {date:item[0].replace(/(\d{4})(\d{2})(\d{2})/,'$1-$2-$3'),value:item[1]};
});
console.log(newArr);