Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.
$scope.arrays= [
            {
                form:'Arrays accessing',
                name:["array1","array2","array3","array4"]
            },

I need to access the array1, array2, array3, array4 in name, I tried below code but i'm getting first array1 only

$scope.addField = {};
$scope.addField.types = $scope.arrays[0].name[0];
share|improve this question

1 Answer

up vote 0 down vote accepted

In JS I would write forEach:

 $scope.arrays.forEach(function(value, index) {     
     for (var i = 0; i < value.name.length; i++) {
         $scope.addField.types.push(value.name[i]);
     }
 }); 

To represent $scope.addField.types in HTML you can use ng-repeat, like:

<li ng-repeat="type in addField.types"></li>

(But sure it will work if above mentioned loop you write into controller)

share|improve this answer
it looks too much code.. to access an object it is working $scope.arrays[0].form; for accessing an array why i need this much code – Ranjith 12 hours ago
right, you have list into list, no way but write two loops, i'll try to make it shorter :), see now – Maxim Shoustin 12 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.