2017-06-20 289 views
0

我想用JavaScript打印驅動程序的名稱,即ravi。我如何迭代這個json數組?如何遍歷JSON數組?

{ 
    "addressL1": "sd", 
    "addressL2": "ds", 
    "addressProof": "fds", 
    "bankAccountNumber": "1235", 
    "city": "bgp", 
    "created": "2017-06-19T14:25:10IST", 
    "dob": "01/03/1996", 
    "driverId": "Rishii kumar", 
    "drivers": { 
     "83c2e6b1-4cae-493e-a142-1d67578b9233": "Ravi kumar", 
     "8be92acf-71a8-46af-b858-3894dd1882b2": "Rishu Kumar", 
     "ff070bd2-a358-403d-9cd0-e3f5986f2e6b": "Ravi Kumar" 
    }, 
    "email": "[email protected]", 
    "fathersName": "das", 
    "identityProof": "sdad", 
    "ifsc": "789", 
    "landline": "8555555", 
    "lastupdated": "2017-06-19T14:39:16IST", 
    "mobile": "8892183052", 
    "name": "Rishu", 
    "pin": "812001", 
    "privacyVersion": "fds", 
    "termsVersion": "" 
} 
+1

...有沒有列在那裏。 – Quentin

+0

https://jsfiddle.net/07f1rkkL/1/ – rad11

回答

0

您可以在下面的代碼中使用地圖功能,如:

var data = { 
 
    "addressL1": "sd", 
 
    "addressL2": "ds", 
 
    "addressProof": "fds", 
 
    "bankAccountNumber": "1235", 
 
    "city": "bgp", 
 
    "created": "2017-06-19T14:25:10IST", 
 
    "dob": "01/03/1996", 
 
    "driverId": "Rishii kumar", 
 
    "drivers": { 
 
     "83c2e6b1-4cae-493e-a142-1d67578b9233": "Ravi kumar", 
 
     "8be92acf-71a8-46af-b858-3894dd1882b2": "Rishu Kumar", 
 
     "ff070bd2-a358-403d-9cd0-e3f5986f2e6b": "Ravi Kumar" 
 
    }, 
 
    "email": "[email protected]", 
 
    "fathersName": "das", 
 
    "identityProof": "sdad", 
 
    "ifsc": "789", 
 
    "landline": "8555555", 
 
    "lastupdated": "2017-06-19T14:39:16IST", 
 
    "mobile": "8892183052", 
 
    "name": "Rishu", 
 
    "pin": "812001", 
 
    "privacyVersion": "fds", 
 
    "termsVersion": "" 
 
}; 
 

 
var results = Object.keys(data.drivers).map(e => data.drivers[e]); 
 
console.log(results);