user2851669 user2851669 - 6 months ago 98
AngularJS Question

looping multiple arrays simultaneously with ng-repeat

Can I traverse two arrays simultaneously using only one

in AngularJs? If so, then how?

For example I have two arrays

array1 = [1,2,3,4,5]

array2 = [6,7,8,9,10]

It should be able to produce the same index for both the arrays.


If you want to acces the second array with the index of the first, try this:

$scope.arr1 = [1, 2, 3, 4, 5]
$scope.arr2 = [6, 7, 8, 9, 10]

<div ng-repeat="number in arr1">
    Number from array1 = {{number}}
    Number from array2 = {{arr2[$index]}}

See this fiddle: