返回数据-----数组处理
Posted alizhi
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了返回数据-----数组处理相关的知识,希望对你有一定的参考价值。
一:数组重构,将返回的数组重构成自己想要的结构;
//后台返回的数据
var dataArr =
[
"id": 1799,
"activity_name": "小彬彬啊啊啊",
"group_num": 1,
"group_member_num": 0
,
"id": 1800,
"activity_name": "中华人民共和国测试部",
"group_num": 1,
"group_member_num": 0
,
"id": 1803,
"activity_name": "慕容",
"group_num": 1,
"group_member_num": 0
,
"id": 1806,
"activity_name": "姜致斌测试",
"group_num": 1,
"group_member_num": 0
,
"id": 1807,
"activity_name": "姜大肥",
"group_num": 1,
"group_member_num": 0
]
//转换
let ydata = [];
let xdata = [];
for (let i = 0; i < dataArr.length; i++)
ydata[i] =
name: dataArr[i].activity_name,
value: dataArr[i].group_num
;
xdata[i] = dataArr[i].activity_name;
二:数组去重,排序,获取最大值;
三:数组日期处理
var dataTime = "20190713".replace(/^(\d4)(\d2)(\d2)$/, "$1-$2-$3");
alert(dataTime);//2019-07-13
//日期处理
var time = "21090713"
var dataTime2 = time.toString().replace(/^(\d4)(\d2)(\d2)$/, "$2-$3");
alert(dataTime2);//07-13
以上是关于返回数据-----数组处理的主要内容,如果未能解决你的问题,请参考以下文章