angularjs - use of angular.forEach instead of for -


i new angularjs, please tell how use angular.foreach below code

for(i=0;i<$scope.data.tabs.length;i++){     $scope.data.tabs[i]['position']=i+1; } 

you have remember that...

the iterator function invoked iterator(value, key, obj)

see https://docs.angularjs.org/api/ng/function/angular.foreach

angular.foreach($scope.data.tabs, function(tab, i) {     tab.position = + 1; }); 

so here, tab value of $scope.data.tabs[i] , i index of each tab in array.


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -