How to iterate over the keys and values with ng-repeat in AngularJS ? Last Updated : 12 Jul, 2025 Comments Improve Suggest changes 1 Likes Like Report The task is to iterate over a JS object (its keys and values) using the ng-repeat directive. This can be done using parenthesis in the ng-repeat directive to explicitly ask for a key-value pair parameter from angularJS. Here the variable key contains the key of the object and value contains the value of the object. Syntax: <element ng-repeat="(key, value) in JSObject"> Contents... </element>Example 1: In this example, we will simply display all the keys and values of a JS object using ng-repeat. In first iteration, key = name and value = "GeeksforGeeks". In the 2nd iteration, key = location and value = "Noida India Sector 136"...This keeps on iterating until all the keys and their values are covered at least once similar to a for-each loop. HTML <!DOCTYPE html> <html ng-app="myApp"> <head> <script src= "https://ajax.googleapis.com/ajax/libs/angularjs/1.7.8/angular.min.js"> </script> </head> <body ng-controller="MyController"> <center> <h1 style="color: green;"> GeeksforGeeks </h1> <h3> Iterating the keys & values with ng-repeat in AngularJS </h3> <div ng-repeat="(key, value) in gfg">\ <!-- First Iteration--> <p>{{key}} - {{value}}</p> </div> </center> <script type="text/javascript"> var myApp = angular.module('myApp', []); myApp.controller('MyController', ['$scope', function($scope) { $scope.gfg = { Name: "GeeksforGeeks", Location: "Noida India Sector 136", Type: "Edu-Tech", } }]); </script> </body> </html> Output: On loading the page, we see that all the key-value pairs of the objects are already listed there. This is because the ng-repeat is called on load as the HTML gets loaded. Example 2: In this example, we will loop over a nested object using the ng-repeat directive. In the first iteration, key = diamond and value = {hardness:"Ultra Hard", goodFor:"Display, cutting"} in the next iteration key = gold and value is its respective object. This keeps on iterating like a for-each loop over the key-value pairs of the object materials. HTML <!DOCTYPE html> <html ng-app="myApp"> <head> <script src= "https://ajax.googleapis.com/ajax/libs/angularjs/1.7.8/angular.min.js"> </script> </head> <body ng-controller="MyController"> <center> <h1 style="color: green;"> GeeksforGeeks </h1> <h3> Iterating the keys & values with ng-repeat in AngularJS </h3> <div ng-repeat="(key, value) in materials"> <h1>{{key}}</h1> <div ng-repeat="(key1, value1) in value"> <!-- since the "value" variable itself is an object. We can iterate over its keys and values again using ng-repeat. --> <p>{{key1}} - {{value1}}</p> </div> </div> </center> <script type="text/javascript"> var myApp = angular.module('myApp', []); myApp.controller('MyController', ['$scope', function($scope) { $scope.materials = { diamond: { hardness: "Ultra Hard", goodFor: "Display, cutting" }, gold: { hardness: "Hard", goodFor: "Jewelry" }, silver: { hardness: "comparatively soft", goodFor: "Jewelry, Display" } } }]); </script> </body> </html> Output: Create Quiz Comment T thvardhan Follow 1 Improve T thvardhan Follow 1 Improve Article Tags : Web Technologies AngularJS AngularJS-Questions Explore AngularJS BasicsAngularJS Tutorial 5 min read Introduction to AngularJS 4 min read Angular CLI | Angular Project Setup 3 min read AngularJS Expressions 2 min read AngularJS Modules 3 min read AngularJS ng-model Directive 4 min read AngularJS Data Binding 4 min read AngularJS Controllers 3 min read AngularJS | Scope 2 min read AngularJS Services 4 min read AngularJS | AJAX - $http 3 min read AngularJS | Tables 2 min read AngularJS Select Boxes 2 min read AngularJS SQL 3 min read AngularJS HTML DOM 2 min read AngularJS Events 3 min read AngularJS | Forms 3 min read AngularJS Form Validation 3 min read AngularJS | API 2 min read AngularJS and W3.CSS 2 min read AngularJS Includes 3 min read AngularJS Animations 1 min read AngularJS | Application 3 min read AngularJS DirectivesAngularJS Directives 9 min read AngularJS ng-app Directive 1 min read AngularJS ng-bind Directive 2 min read AngularJS ng-bind-html Directive 2 min read AngularJS ng-bind-template Directive 2 min read AngularJS ng-blur Directive 1 min read AngularJS ng-change Directive 2 min read AngularJS ng-checked Directive 2 min read AngularJS ng-class Directive 2 min read AngularJS ng-class-even Directive 2 min read AngularJS ng-class-odd Directive 2 min read AngularJS ng-click Directive 2 min read AngularJS ng-cloak Directive 2 min read AngularJS ng-controller Directive 2 min read AngularJS Directives Complete Reference 2 min read AngularJS FiltersAngularJS | Filters 7 min read AngularJS currency Filter 2 min read AngularJS | date Filter 2 min read AngularJS filter Filter 3 min read AngularJS json Filter 2 min read AngularJS limitTo Filter 2 min read AngularJS lowercase Filter 1 min read AngularJS number Filter 1 min read AngularJS orderBy Filter 4 min read AngularJs uppercase Filter 1 min read AngularJS Converting FunctionsAngularJS angular.lowercase() Function 2 min read AngularJS angular.uppercase() Function 1 min read AngularJS angular.forEach() Function 1 min read AngularJS Comparing FunctionsAngularJS angular.isArray() Function 2 min read AngularJS angular.isDate() Function 2 min read AngularJS angular.isDefined() Function 2 min read AngularJS angular.isElement() Function 2 min read AngularJS angular.isFunction() Function 2 min read AngularJS angular.isNumber() Function 2 min read AngularJS angular.isObject() Function 2 min read AngularJS | angular.isString() Function 1 min read AngularJS angular.isUndefined() Function 2 min read AngularJS angular.equals() Function 2 min read AngularJS angular.toJson() Function 2 min read AngularJS QuestionsHow to bundle an Angular app for production? 4 min read How to add many functions in one ng-click directive? 2 min read How to directly update a field by using ng-click in AngularJS ? 3 min read How to Add Dynamic Options for Multiple Selects Inside ng-repeat Directive ? 3 min read How to detect when an @Input() value changes in Angular? 3 min read How to open popup using Angular and Bootstrap ? 2 min read How to reload or re-render the entire page using AngularJS? 2 min read How to add input fields dynamically on button click in AngularJS ? 2 min read How to Create Button Dynamically with Click Event in Angular ? 2 min read How to use jQuery in Angular ? 2 min read AngularJS Examples 2 min read Like