복잡한 자바 스크립트 개체 내부에서 문자열 속성을 추출해야합니다.
내 시나리오는 다음과 같습니다.
for (var key in results) {
console.log(results[key]);
...results[key] is an object that returns few arrays and properties
...i need to capture an array inside named "all_names"
...again loop through all the objects in the array "all_names"
...all the objects have a property name called "first_name"
...i need to capture the "first_name" that have the value "Paul"
}
샘플 데이터 :
console.log (results [key]); 이후
"all_names": Array [7]
주소 : "Some Address"
org_number : "TV146"
그런 다음 "all_names"
"first_name": "Paul"
"last_name": "Henson"을 반복합니다 .
"폴"캡처
도와주세요.
배열 속성이있을 때마다 for (var x in arr)
결과와 함께 사용할 수 있습니다 . 설명에서 예제 개체가 없으면 다음이 있습니다.
results[].all_names[].first_name
주는
for (var key in results)
{
//...results[key] is an object that returns few arrays and properties
//...I need to capture an array inside named "all_names"
//...loop through all the objects in the array "all_names"
for (var namekey in results[key].all_names)
{
// all the objects have a property name called "first_name"
// ...i need to capture the "first_name" that have the value "Paul"
if (results[key].all_names[namekey].first_name == 'Paul') {
// will always be "Paul"
console.log(results[key].all_names[namekey].first_name);
//perhaps: console.log(key);
}
}
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다