Imagine the scenario where you have a JSON string as shown below:
var jsonString = '[{"name":"Tokyo","zone_id":"1","totalagents":"40","agents":[{"id":"1","agent_code":"*****"},{"id":"2","agent_code":"*****"},{"id":"3","agent_code":"Sakura"},{"id":"4","agent_code":"Hiro"},{"id":"5","agent_code":"Yoshi Takahashi"},{"id":"6","agent_code":"*****"},{"id":"7","agent_code":"Kenji"},{"id":"8","agent_code":"Taro"},{"id":"9","agent_code":"Ryuichi"},{"id":"10","agent_code":"Miyamoto"},{"id":"11","agent_code":"*****"},{"id":"16","agent_code":"Sakura2"},{"id":"20","agent_code":"Kenta"},{"id":"21","agent_code":"Shinji"},{"id":"22","agent_code":"Daiki"},{"id":"23","agent_code":"Ayumi"},{"id":"24","agent_code":"Emi"},{"id":"25","agent_code":"Aiko "},{"id":"26","agent_code":"Junko"},{"id":"27","agent_code":"Mari"},{"id":"28","agent_code":"Haru"},{"id":"29","agent_code":"Yuki Takahashi"},{"id":"30","agent_code":"Hideki"},{"id":"31","agent_code":"Naoko"},{"id":"32","agent_code":"Rina"},{"id":"33","agent_code":"Kaito"},{"id":"37","agent_code":"Akira"},{"id":"39","agent_code":"Nori Yamada"},{"id":"40","agent_code":"Taichi"},{"id":"41","agent_code":"Ryo "},{"id":"44","agent_code":"Hikaru"},{"id":"45","agent_code":"Kaoru"},{"id":"46","agent_code":"Go"},{"id":"47","agent_code":"Junpei"},{"id":"49","agent_code":"Michihiro Sato"},{"id":"50","agent_code":"Takeshi Suzuki"},{"id":"51","agent_code":"Tomoya Tanaka"},{"id":"52","agent_code":"Sora Ueno"},{"id":"53","agent_code":"Kazuo Yoshida"}]}]';
var json = JSON.parse(jsonString); // parse string into JSON
Now, since this JSON is an array with a length of 1, to extract all agent codes, you can use the following loop:
for (var i = 0; i <json[0].agents.length; i++) {
console.log(json[0].agents[i].agent_code);
}