How to select first object in object in AngularJS? Last Updated : 18 Sep, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report The main problem that we are dealing with is that for an object of objects reading the object of a particular index position is not as simple as a list. We cannot loop over it using ngFor as an object is not considered an iterable. The importance of this issue may arise when the data received from any source is an object containing objects(like JSON files). Altering the source file is very inconvenient so we need to be able to do something in the application itself. The most effective way is hidden in the problem itself. If objects are not iterable, then convert them to iterable. The following are 2 approaches that can be utilized to select the first object in object in AngularJS, which is described below: Approach 1: Using the ng-repeat Directive and the limitTo FilterThe ng-repeat is able to iterate over the properties of objects which in our case are objects themselves. The following syntax is used:<div ng-repeat="(key, value) in myObj"> ... </div>limitTo filter creates a new array or string containing only a specified number of elements. The elements are taken from either the beginning or the end of the source array, string, or number, as specified by the value and sign (positive or negative) of the limit. The following syntax will be used to bind the HTML:{{ limitTo_expression | limitTo : limit : begin}}Example 1: In this example, the value of the limit can be changed to get the element(object in this case) of the iterable. HTML <!DOCTYPE html> <html> <head> <title> Angular first object in object </title> <script src= "https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"> </script> </head> <body ng-app='MyApp' ng-controller='MyCtrl'> <div ng-repeat="(key, obj) in institute | limitTo : 1"> <ul> <li ng-repeat="(prop, value) in obj"> {{prop}}: {{value}} </li> </ul> </div> <script> var app = angular.module('MyApp', []); app.controller('MyCtrl', function($scope) { $scope.institute = { 'school': { location: 'Jamshedpur', name: 'RV' }, 'college': { location: 'Kolkata', name: 'Jadavpur' } }; var instilist = new Array(); for (key of Object.keys($scope.institute)) { instilist.push($scope.institute[key]); } $scope.institute = instilist; }); </script> </body> </html> Output: Approach 2Convert the object of objects into an array of objects and use the indexing method of square brackets([]) to display the first object of the array. Syntax: {{name_of_the array[index]}}Example 2: In this example, the value of the index is 0 for the first object of the array. Since the elements of the array are objects we can refer to the properties of the objects using the (.) operator. HTML <!DOCTYPE html> <html> <head> <title> Angular first object in object </title> <script src= "https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"> </script> </head> <body> <div ng-app="MyApp" ng-controller="MyCtrl"> <p> The Name of the school is: {{institute[0].name}} </p> </div> <script> var app = angular.module('MyApp', []); app.controller('MyCtrl', function($scope) { $scope.institute = { school: { location: 'Jamshedpur', name: 'RV' }, college: { location: 'Kolkata', name: 'Jadavpur' } }; var instilist = new Array(); for (key of Object.keys($scope.institute)) { instilist.push($scope.institute[key]); } $scope.institute = instilist; }); </script> </body> </html> Output: Comment More infoAdvertise with us A anushil8991 Follow Improve Article Tags : Web Technologies AngularJS AngularJS-Misc Similar Reads Non-linear Components In electrical circuits, Non-linear Components are electronic devices that need an external power source to operate actively. Non-Linear Components are those that are changed with respect to the voltage and current. Elements that do not follow ohm's law are called Non-linear Components. Non-linear Co 11 min read JavaScript Tutorial JavaScript is a programming language used to create dynamic content for websites. It is a lightweight, cross-platform, and single-threaded programming language. It's an interpreted language that executes code line by line, providing more flexibility.JavaScript on Client Side: On the client side, Jav 11 min read Web Development Web development is the process of creating, building, and maintaining websites and web applications. It involves everything from web design to programming and database management. Web development is generally divided into three core areas: Frontend Development, Backend Development, and Full Stack De 5 min read Spring Boot Tutorial Spring Boot is a Java framework that makes it easier to create and run Java applications. It simplifies the configuration and setup process, allowing developers to focus more on writing code for their applications. This Spring Boot Tutorial is a comprehensive guide that covers both basic and advance 10 min read React Interview Questions and Answers React is an efficient, flexible, and open-source JavaScript library that allows developers to create simple, fast, and scalable web applications. Jordan Walke, a software engineer who was working for Facebook, created React. Developers with a JavaScript background can easily develop web applications 15+ min read React Tutorial React is a powerful JavaScript library for building fast, scalable front-end applications. Created by Facebook, it's known for its component-based structure, single-page applications (SPAs), and virtual DOM,enabling efficient UI updates and a seamless user experience.Note: The latest stable version 7 min read JavaScript Interview Questions and Answers JavaScript is the most used programming language for developing websites, web servers, mobile applications, and many other platforms. In Both Front-end and Back-end Interviews, JavaScript was asked, and its difficulty depends upon the on your profile and company. Here, we compiled 70+ JS Interview q 15+ min read Class Diagram | Unified Modeling Language (UML) A UML class diagram is a visual tool that represents the structure of a system by showing its classes, attributes, methods, and the relationships between them. It helps everyone involved in a projectâlike developers and designersâunderstand how the system is organized and how its components interact 12 min read Backpropagation in Neural Network Back Propagation is also known as "Backward Propagation of Errors" is a method used to train neural network . Its goal is to reduce the difference between the modelâs predicted output and the actual output by adjusting the weights and biases in the network.It works iteratively to adjust weights and 9 min read 3-Phase Inverter An inverter is a fundamental electrical device designed primarily for the conversion of direct current into alternating current . This versatile device , also known as a variable frequency drive , plays a vital role in a wide range of applications , including variable frequency drives and high power 13 min read Like