self.previewApplicationsScreeningQuestions = ko.computed(function () {
return ko.utils.arrayMap(self.applications(), function (i) {
if (i.application.applicationKey == self.previewApplicationKey())
return i.application.applicantScreeningQuestionsAndResponses[0];
});
});
I declared a viewModel like this. What it does is, it basically loops through the "applications" viewModel and returns its "applicantScreeningQuestionsAndResponses[0]" object when a specific condition is met(not important in this question).
When I check the result of this in the console, it gives me.
[Object, undefined, undefined, undefined, undefined, undefined, undefined]
I just want to remove all undefined index and just leave one [Object] in the viewModel. How can I fix this?
EDIT:
self.previewApplicationsScreeningQuestions = ko.computed(function () {
return ko.utils.arrayMap(self.applications(), function (i) {
if (i.application.applicationKey == self.previewApplicationKey())
var arr = i.application.applicantScreeningQuestionsAndResponses[0];
});
var newArr = new Array();
for (var i = 0; i < arr.length; i++) {
if (arr[i]) {
newArr.push(arr[i]);
}
}
return newArr;
});
This returns all 'undefined'