let obj ={
"stepInfo": {
"companyChannel": [
"1",
"2",
"3"
],
"promotionSteps": [
{
"companyFirstChargeAmount": 12,
"companyFirstChargeAmount1": 122,
"mainStep": true,
"returnBcoupon": [
{
"fastCarBatchId": "1228",
"fastCarNumber": 124,
"batchId": "11",
"number": 129,
"replaceFastCarCoupon": 1
},
{
"batchId": "1234"
}
],
"sms": {
"templateId":"11"
},
}
],
"stepCrowdTag": "1001271955"
}
}
function test(obj){
Object.keys(obj).map(item=>{
if(obj[item] && obj[item].constructor === Object){
obj[item][item] = true
console.log(obj[item])
}
})
}
test(obj)
[
{
"stepInfo_companyChannel": ""
},
{
"stepInfo_promotionSteps<0>_mainStep": true
},
{
"stepInfo_promotionSteps<0>_minAmount": 100
},
{
"stepInfo_promotionSteps<0>_maxAmount": 200
},
{
"stepInfo_promotionSteps<1>_mainStep": true
},
{
"stepInfo_promotionSteps<1>_minAmount": 200
},
{
"stepInfo_promotionSteps<1>_returnBcoupon<0>_batchId": 10
},
{
"stepInfo_promotionSteps<1>_returnBcoupon<0>_number": 72
},
{
"stepInfo_promotionSteps<1>_returnBcoupon<0>_replaceFastCarCoupon": 1
},
{
"stepInfo_promotionSteps<1>_returnBcoupon<0>_fastCarBatchId": 25
},
{
"stepInfo_promotionSteps<1>_returnBcoupon<0>_fastCarNumber": 29
},
{
"stepInfo_promotionSteps<1>_returnBcoupon": true
},
{
"stepInfo_promotionSteps<2>_mainStep": true
},
{
"stepInfo_promotionSteps<2>_minAmount": 300
},
{
"stepInfo_promotionSteps<2>_returnBcoupon<0>_batchId": 10
},
{
"stepInfo_promotionSteps<2>_returnBcoupon<0>_number": 72
},
{
"stepInfo_promotionSteps<2>_returnBcoupon<0>_replaceFastCarCoupon": 1
},
{
"stepInfo_promotionSteps<2>_returnBcoupon<0>_fastCarBatchId": 25
},
{
"stepInfo_promotionSteps<2>_returnBcoupon<0>_fastCarNumber": 29
},
{
"stepInfo_promotionSteps<2>_returnBcoupon<1>_batchId": 10
},
{
"stepInfo_promotionSteps<2>_returnBcoupon<1>_number": 72
},
{
"stepInfo_promotionSteps<2>_returnBcoupon<1>_replaceFastCarCoupon": 1
},
{
"stepInfo_promotionSteps<2>_returnBcoupon<1>_fastCarBatchId": 25
},
{
"stepInfo_promotionSteps<2>_returnBcoupon<1>_fastCarNumber": 29
},
{
"stepInfo_promotionSteps<2>_returnBcoupon<2>_batchId": 10
},
{
"stepInfo_promotionSteps<2>_returnBcoupon<2>_number": 72
},
{
"stepInfo_promotionSteps<2>_returnBcoupon<2>_replaceFastCarCoupon": 1
},
{
"stepInfo_promotionSteps<2>_returnBcoupon<2>_fastCarBatchId": 25
},
{
"stepInfo_promotionSteps<2>_returnBcoupon<2>_fastCarNumber": 29
},
{
"stepInfo_promotionSteps<2>_returnBcoupon": true
},
{
"stepInfo_promotionSteps": true
},
{
"stepInfo": true
}
]
console