后臺給了我一個數(shù)據(jù)結(jié)構(gòu)作為表頭,我感覺不太好用,想修改一下格式。 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"};這些不太好直接循環(huán)渲染到頁面上。我想大概修改成這樣的結(jié)構(gòu)好處理了dateInfo = [
{week1_start:"2018-09-03",week1_end:"week1_end"},
{week2_start:"2018-09-03",week2_end:"week1_end"} ]一開始的思路是獲取下滑杠前面一樣的做成一個對象最后放到數(shù)組里。但是每次打印發(fā)現(xiàn)都不是想象的那樣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)
}為什么會這樣啊????難道是我的思路錯了嗎
js改變數(shù)據(jù)結(jié)構(gòu)
狐的傳說
2018-09-24 17:21:34