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工作流
- 未来椅子3D产品ComfyUI工作流
- 一位宇航员做在一只乌龟上在星空中游走
- 在白雪覆盖的广阔平原上两只可爱的小猫
- 一支令人难忘的狙击步枪ComfyUI工作流
- 半透明的玻璃苹果ComfyUI工作流
- 树上一个快乐的猕猴桃ComfyUI工作流
- 广阔的沙漠中矗立着一个生锈的巨大头盔
- 一颗柔和的水晶金字塔ComfyUI工作流
猜你喜欢
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!