这。。。。完全没有意义的操作吧。
<script type="text/javascript">
var arr = [
{a:'1',b:[{c:'4',d:'5'},{c:'4',d:'5'}]},
{a:'1',b:[{c:'4',d:'5'}]}
]
var narr = []
for(let i =0i<arr.lengthi++){
let o = {}
let a = arr[i]
o.a= a.a
if(a.b){
let no = o
for(let j=0j<a.b.lengthj++){
let b = arr[i].b[j]
no.c=b.c
no.d=b.d
narr.push(no)
}
}
}
alert(narr)
// [{a:1,c:4,d:3},{a:1,c:4,d:5},{a:1,c:4,d:5}]
</script>
这。。。。完全没有意义的操作吧。
<script type="text/javascript">
var arr = [
{a:'1',b:[{c:'4',d:'5'},{c:'4',d:'5'}]},
{a:'1',b:[{c:'4',d:'5'}]}
]
var narr = []
for(let i =0i<arr.lengthi++){
let o = {}
let a = arr[i]
o.a= a.a
if(a.b){
let no = o
for(let j=0j<a.b.lengthj++){
let b = arr[i].b[j]
no.c=b.c
no.d=b.d
narr.push(no)
}
}
}
alert(narr)
// [{a:1,c:4,d:3},{a:1,c:4,d:5},{a:1,c:4,d:5}]
</script>