javascript - I need to take the inner contents of the JSON response -


i have following code retrieve json response server , working fine.

javascript code :

$http({     method: 'post',     url: 'http://***someurl',     headers: { 'content-type': 'application/json', 'accept': 'application/json'},     data: json.stringify(data)    }) .then(function (response) {     $scope.mydata = response.data;     $scope.mydata1=response.data.message.connectiondetailses; }); 

and response is

{     "code": 100,     "message": {         "id": 29020,         "customercode": "730",         "name": "john p. m.    168",         "lastname": "x",         "housename": "hosuseahjkahsh",         "address1": "1",         "address2": "x",         "address3": "wehwhkjwh p. o.",         "postalcode": "686011",         "email": "11@11.com",         "phone": "1234567890",         "mobile": "1234567890",         "operatorname": "abcd ",         "connectiondetailses": [             {                 "customercode": "730",                 "accountid": 5,                 "dueamount": 0,                 "connectionid": 27203,                 "accountname": "m s"             },             {                 "customercode": "730",                 "accountid": 5,                 "dueamount": 2000,                 "connectionid": 116303,                 "accountname": "ms"             },             {                 "customercode": "730",                 "accountid": 9,                 "dueamount": 0,                 "connectionid": 116303,                 "accountname": "connection"             },             {                 "customercode": "730",                 "accountid": 14,                 "dueamount": 0,                 "connectionid": 116303,                 "accountname": "amc"             }         ]     } } 

i need print connection details based on connectionid. able print connection details @ time. need print details within single block.

{                 "customercode": "730",                 "accountid": 9,                 "dueamount": 0,                 "connectionid": 116303,                 "accountname": "connection" } 

given connectionid, can print corresponding connection detail by:

let connectionid = 116303 let connectiondetail = response.data.message.connectiondetailses.find(det => det.connectionid === connectionid); console.log(connectiondetail); 

in case want details based on same id, can use array.filter:

let connectionid = 116303 let connectiondetails = response.data.message.connectiondetailses.filter(det => det.connectionid === connectionid); console.log(connectiondetails); 

Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -