---
lang: en
title: 'API docs: context.comparebyorder'
keywords: LoopBack 4.0, LoopBack 4
sidebar: lb4_sidebar
permalink: /doc/en/lb4/apidocs.context.comparebyorder.html
---

<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@loopback/context](./context.md) &gt; [compareByOrder](./context.comparebyorder.md)

## compareByOrder() function

Compare two values by the predefined order

<b>Signature:</b>

```typescript
export declare function compareByOrder(a: string | symbol | undefined | null, b: string | symbol | undefined | null, order?: (string | symbol)[]): number;
```

## Parameters

|  Parameter | Type | Description |
|  --- | --- | --- |
|  a | <code>string &#124; symbol &#124; undefined &#124; null</code> | First value |
|  b | <code>string &#124; symbol &#124; undefined &#124; null</code> | Second value |
|  order | <code>(string &#124; symbol)[]</code> | An array of values as the predefined order |

<b>Returns:</b>

`number`

## Remarks

The comparison is performed as follows:

1. If both values are included in `order`<!-- -->, they are sorted by their indexes in `order`<!-- -->. 2. The value included in `order` comes after the value not included in `order`<!-- -->. 3. If neither values are included in `order`<!-- -->, they are sorted: - symbol values come before string values - alphabetical order for two symbols or two strings


