后台给了我一个数据结构作为表头,我感觉不太好用,想修改一下格式。
var dateInfo = { week1_end: "2018-09-09", week1_start: "2018-09-03", week2_end: "2018-09-16", week2_start: "2018-09-10", week3_end: "2018-09-23", week3_start: "2018-09-17", week4_end: "2018-09-30", week4_start: "2018-09-24", week5_end: "2018-10-07", week5_start: "2018-10-01"};
这些不太好直接循环渲染到页面上。我想大概修改成这样的结构好处理了
dateInfo = [ {week1_start:"2018-09-03",week1_end:"week1_end"}, {week2_start:"2018-09-03",week2_end:"week1_end"} ]
一开始的思路是获取下滑杠前面一样的做成一个对象最后放到数组里。但是每次打印发现都不是想象的那样
var new_arr = []for(item in dateInfo){ // console.log(item) var str1 = item.match(/(\S*)_/)[1]; if (item.includes(str1)) { var obj = { item : dateInfo[item] } } new_arr.push(obj) }
为什么会这样啊????难道是我的思路错了吗
烙印99