← All pipes
Utilities

invertRecord

Invert scalar mappings while preserving duplicate-value keys.

Use it in your component

Standalone component
import { Component } from '@angular/core';
import { JsonPipe } from '@angular/common';
import { InvertRecordPipe } from 'extra-pipe';

@Component({
  standalone: true,
  imports: [InvertRecordPipe, JsonPipe],
  template: `{{ {"a":"x","b":"x"} | invertRecord | json }}`,
})
export class ExampleComponent {

}

Template
{{ {"a":"x","b":"x"} | invertRecord | json }}

Try it live.

The output below runs the packed library. Edit data, not code.

Use double quotes for text, or a number, array, object or null.
No parameters: use []. Locale is controlled separately.
This pipe has no locale override.
Live template data
readonly value = {
  "a": "x",
  "b": "x"
} as const;

{{ value | invertRecord | json }}

Rendered output

{
  "x": [
    "a",
    "b"
  ]
}