2014-07-20 2 views

답변

8

당신은 각각의 모든 객체를 통해이

x["answers"].forEach(function(currentObject) { 
    currentObject["response"] = null; 
}); 

처럼 객체에이 반복을 새로운 속성을 추가하고 각각에 response 속성을 추가 할 수 있습니다.

+0

이 JQuery와 권리를 요구한다? – Ota

+2

forEach는 네이티브 javascript – hutingung

+4

@Otanaught ECMAScript 5.1을 지원하는 브라우저가 필요합니다. ['Array.prototype.forEach'] (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/) Global_Objects/Array/forEach) –

3

일반 자바 스크립트 :

for (key in x['answers']) { 
    x['answers'][key]['response'] = null; 
} 
+1

'for..in'을 사용하여 배열을 반복하는 것은 좋지 않습니다. – thefourtheye

+0

@thefourtheye 이유를 설명해 주시겠습니까? – Ota

+1

[이 섹션] (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in#Description)의 박스 항목을 확인하십시오. – thefourtheye

관련 문제