1、默认数据
var arr1 = [{ color1: "#e35752", color2: "#fb995f", data:[22223286, 6919184, 4227231, 985484, 242569], name: "超声", type: ["门诊", "住院", "体检", "急诊", "外院"] },{ color1: "#e35752", color2: "#fb995f", data:[22223286, 6919184, 4227231, 985484, 242569], name: "CT", type: ["门诊", "住院", "体检", "急诊", "外院"] }]
2、遍历方法
function getDataArr(data) { var resData = [] data.forEach(function(item, index) { if(item.data && item.data.length>0){ var _d = item.data var _t = item.type _d.forEach(function(ditem,index){ var _obj = JSON.parse((JSON.stringify(item))) _obj.data = ditem _obj.type = _t[index] resData.push(_obj) }) } }) return resData }
3、执行方法
getDataArr(arr1)
4、返回结果
0: {color1: "#e35752", color2: "#fb995f", data: 22223286, name: "超声", type: "门诊"} 1: {color1: "#e35752", color2: "#fb995f", data: 6919184, name: "超声", type: "住院"} 2: {color1: "#e35752", color2: "#fb995f", data: 4227231, name: "超声", type: "体检"} 3: {color1: "#e35752", color2: "#fb995f", data: 985484, name: "超声", type: "急诊"} 4: {color1: "#e35752", color2: "#fb995f", data: 242569, name: "超声", type: "外院"} 5: {color1: "#e35752", color2: "#fb995f", data: 22223286, name: "CT", type: "门诊"} 6: {color1: "#e35752", color2: "#fb995f", data: 6919184, name: "CT", type: "住院"} 7: {color1: "#e35752", color2: "#fb995f", data: 4227231, name: "CT", type: "体检"} 8: {color1: "#e35752", color2: "#fb995f", data: 985484, name: "CT", type: "急诊"} 9: {color1: "#e35752", color2: "#fb995f", data: 242569, name: "CT", type: "外院"}
上面是“js把多维数组的子集数组全部遍历成同级”的全面内容,想了解更多关于 js 内容,请继续关注web建站教程。
当前网址:https://ipkd.cn/webs_1443.html
workflows工作流
- 一个20岁丰满的女孩ComfyUI工作流
- stvmccrr风格的玫瑰花ComfyUI工作流
- 一尊白玉猴王ComfyUI工作流
- 汉堡里的一只毛茸茸的小猫ComfyUI工作流
- 大黄蜂空中决战ComfyUI工作流
- 一杯咖啡蒸汽形成云ComfyUI工作流
- 文生图工作流:图片合并comfyui工作流
- 一只蚂蚁在花丛中找食物ComfyUI工作流
猜你喜欢
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!