Skip to content Skip to sidebar Skip to footer

TypeError: $scope.array.reduce Is Not A Function

I have 3 drop-down-lists that load attributes related to a page. These attributes are: instruments, style, scoring. The attributes are loaded from a service call. Example using in

Solution 1:

I ended up not using .reduce anymore. I changed the code to use a for loop after posting a new question and getting a working answer: JavaScript: flatten an array without using reduce library

Here is the code snippet that replaces the reduce function:

if (attribute == 1) {

    var arrInstruments = $scope.instruments;
    var arrLength = arrInstruments.length;
    var result = {}
    for (var i = 0; i < arrLength; i++) {
        result[arrInstruments[i].ID] = arrInstruments[i];
    }
    $scope.recordInstrument = result[$scope.newpage.AttributeID[0]].ID;
}

Solution 2:

It looks like your problem is here.

});
// you have a closing bracket missing
    }else {
        $scope.recordInstrument = 0;
    }
}).error(function () {
    $scope.error = "An Error has occured while Editing this Store Page!" + data;
});

Fixed

});
  };  // added a close bracket
    }else {
        $scope.recordInstrument = 0;
    }
}).error(function () {
    $scope.error = "An Error has occured while Editing this Store Page!" + data;
});

Post a Comment for "TypeError: $scope.array.reduce Is Not A Function"