0

So in my controller I have these arrays with object items in them:

$scope.johnny = [
    {quote: "Anything for My Princess", path: 'sounds/AnythingForMyPrincess.mp3'},
    {quote: "Don't Even Ask", path: 'sounds/DontEventAsk.mp3'},
    {quote: "Don't Plan Too Much", path: 'sounds/DontPlanTooMuch.mp3'}
] //there are many more lists like this one

and I would like to go through these lists by using another array (names of array) and a for loop:

$scope.totalNames = [$scope.johnny, $scope.lisa, $scope.mark, $scope.denny, $scope.lisasmom, 
                    $scope.chicken, $scope.chris, $scope.flower, $scope.mike, $scope.steven]

for (var i = 0; i < $scope.totalNames.length; i++) {
    var list = $scope.totalNames[i];
    alert(list.quote);
}

$scope.totalNames[i] returns the correct array; however once I add the .quote to it the it returns undefined. Any ideas? Thanks

1 Answer 1

2

$scope.totalNames is a list of list. You should so this:

for (var i = 0; i < $scope.totalNames.length; i++) {
    var list = $scope.totalNames[i];
    for (var j = 0; j < list.length; j++) {
        alert(list[j].quote);
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

My bad, didn't see that one. Thanks a lot.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.