개체가 가득 찬 questionSets 배열이 있습니다. createSet 함수는 new를 만들거나 기존 questionSets 객체의 복사본을 만들어야합니다. getQuestionsFromSet 함수는 createSet을 사용하여 복사를하는 경우에 사용됩니다. 어떤 이유로 나는 createSet() 내부에서 getQuestionsFromSet()을 호출 할 때 항상 반환되는 'undefined'값을 얻습니다. 나는 왜 내가 원하는 것을 정확히 볼 수 있기 때문에, getQuestionsFromSet()에 의해 리턴 될 값의 console.log()를 할 것이기 때문에 이유를 알 수 없다.반환 값이 정의되지 않은 이유 (JavaScript)
나는이 두 가지 기능을 가지고 있습니다.
function createSet(name, copiedName) {
var questions = [];
if (copiedName) {
questions = getQuestionsFromSet(copiedName);
}
console.log(questions); // undefined. WHY??
questionSets.push({
label: name,
value: questions
});
}; // end createSet()
function getQuestionsFromSet(setName) {
$.each(questionSets, function (index, obj) {
if (obj.label == setName) {
console.log(obj.value); // array with some objects as values, which is what I expect.
return obj.value;
}
});
}; // end getQuestionsFromSet()
console.log에 값이 있습니까? –
@AnkitJaiswal 아약스 호출이 없습니다! – epascarello