How to Sort an Array of Objects by String Property value in Angular ? Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report An Object is a collection of properties, and a property is an association between a name (or key) and a value. A property's value can be a function, in which case the property is known as a method. In this article, we will learn how to Sort an array of objects by string property value in Angular. Here, we will sort the object based on the property value of the object rather than the key. Steps for Installing & Configuring the Angular Application Step 1: Create an Angular application using the following command. ng new appname Step 2: After creating your project folder i.e. appname, move to it using the following command. cd appnameProject Structure  It will look like the following: Example 1: In this example, we will create a sort function that will sort the property values. HTML <!-- app.component.html --> <h2 style="color: green"> GeeksforGeeks </h2> <h2> Sort array of objects by string property value in Angular </h2> <div *ngFor="let item of gfg"> <b>Key:  </b>{{item.key}}  <b>Value :  </b>{{item.value}} </div> JavaScript // app.component.ts import { Component, OnInit } from '@angular/core'; import { KeyValue } from '@angular/common'; import { Pipe, PipeTransform } from '@angular/core'; @Component({ selector: 'app-root', templateUrl: "./app.component.html", styleUrls: ['./app.component.css'] }) export class AppComponent implements OnInit { gfg: any = [ { key: "3", value: "1700" }, { key: "4", value: "1900" }, { key: "2", value: "1400" }, { key: "1", value: "1300" }, { key: "7", value: "1200" }, { key: "9", value: "1800" }, { key: "8", value: "2100" }, { key: "5", value: "1100" } ] ngOnInit() { this.gfg.sort(function (a: any, b: any) { return a.value - b.value; }) } } JavaScript // app.module.ts import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { HttpClientModule } from '@angular/common/http'; import { AppComponent } from './app.component'; @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, HttpClientModule, ], providers: [], bootstrap: [AppComponent] }) export class AppModule { } Output: Example 2: In this example, we will sort the property values using localecompare. It is an inbuilt method in JavaScript that is used to compare any two elements and returns a positive number if the reference string is lexicographically greater than the compare string and a negative number if the reference string is lexicographically smaller than the compare string and zero (0) if the compare and reference strings are equivalent. HTML <!-- app.component.html --> <h2 style="color: green"> GeeksforGeeks </h2> <h2> Sort array of objects by string property value in Angular </h2> <div *ngFor="let item of gfg"> <b>Key:  </b>{{item.key}}  <b>Value :  </b>{{item.value}} </div> JavaScript // app.component.ts import { Component, OnInit } from '@angular/core'; import { KeyValue } from '@angular/common'; import { Pipe, PipeTransform } from '@angular/core'; @Component({ selector: 'app-root', templateUrl: "./app.component.html", styleUrls: ['./app.component.css'] }) export class AppComponent implements OnInit { gfg: any = [ { key: "3", value: "1700" }, { key: "4", value: "1900" }, { key: "2", value: "1400" }, { key: "1", value: "1300" }, { key: "7", value: "1200" }, { key: "9", value: "1800" }, { key: "8", value: "2100" }, { key: "5", value: "1100" } ] ngOnInit() { this.gfg.sort((a: any, b: any) => a.value.localeCompare(b.value)); } } JavaScript // app.module.ts import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { HttpClientModule } from '@angular/common/http'; import { AppComponent } from './app.component'; @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, HttpClientModule, ], providers: [], bootstrap: [AppComponent] }) export class AppModule { } Output: Comment More infoAdvertise with us Next Article How to Sort an Array of Objects by String Property value in Angular ? 21mcsrltd Follow Improve Article Tags : Web Technologies AngularJS AngularJS-Questions Similar Reads How to sort an array of objects by property values ? In this article, we will try to understand how to sort an array of objects by property values in JavaScript with the help of certain examples. Pre-requisite: Array of Objects in JavaScript Example: Input:[ { name: "Ram", age: 17 }, { name: "Mohan", age: 30 }, { name: "Shyam", age: 15 }, { name: "Shy 4 min read Sort Array of Objects By String Property Value in JavaScript Sorting arrays of objects based on a string property can be helpful for handling user data or dynamic lists. Here are different ways to sort an array of Objects By String Property Value.1. Using localeCompare() Method â Most UsedThe JavaScript localeCompare() method returns a number indicating wheth 3 min read How to Sort an Array of Object using a Value in TypeScript ? Sorting an array of objects using a value in TypeScript pertains to the process of arranging an array of objects in a specified order based on a particular property or value contained within each object. The below approaches can be used to sort an array of objects using a value in TypeScript: Table 3 min read Sort an array of objects using Boolean property in JavaScript Given the JavaScript array containing Boolean values. The task is to sort the array on the basis of Boolean value with the help of JavaScript. There are two approaches that are discussed below: Table of Content Using Array.sort() Method and === OperatorUsing Array.sort() and reverse() MethodsUsing a 2 min read Sort Array of Objects by Property with Undefined Values in TypeScript In TypeScript, sorting an array of objects by property with undefined values by comparing the defined values precedes those with the undefined ones. Below are the approaches to sort the array of objects by property with undefined values in TypeScript: Table of Content Using Array.reduce and findInde 4 min read How to Sort an Array of Objects with Null Properties in TypeScript ? Sorting an array of objects in TypeScript involves arranging objects based on specified properties. When dealing with null properties, ensure consistency by placing them either at the start or end of the sorted array to maintain predictability in sorting outcomes. Below are the approaches used to so 5 min read How to Sort an Array based on User Input in AngularJS ? AngularJS is a JavaScript-based framework. It can be used by adding it to an HTML page using a <script> tag. AngularJS helps in extending the HTML attributes with the help of directives and binding of data to the HTML with expressions. In this article, we will see how to sort an array based o 3 min read How to Sort Objects in an Array Based on a Property in a Specific Order in TypeScript ? Sorting objects in an array based on a specific property is a common task in software development. TypeScript, with its static typing and powerful features, provides various approaches to accomplish this task efficiently. The below approaches can be used to sort an array of objects in properties. Ta 3 min read How to filter by object property in AngularJS? Filtering by object property in AngularJS is the concept of choosing the specific objects from the data array which is based on the individual properties. In creating a web application, this is the most common task that deals with the data that needs to be sorted and then displayed to the user. Deve 6 min read How to Sort JSON Array in JavaScript by Value ? Sorting is the process of arranging elements in a specific order. In JavaScript, you can sort a JSON array by value using various methods as listed and discussed below with their practical implementation. Table of Content Using sort() FunctionUsing Array.prototype.reduce()Using Bubble SortUsing sort 3 min read Like