Skip to content

Instantly share code, notes, and snippets.

@JonathanDn
Created November 3, 2016 08:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JonathanDn/3b8700caeebb8e9f6b311214cf015f11 to your computer and use it in GitHub Desktop.
Save JonathanDn/3b8700caeebb8e9f6b311214cf015f11 to your computer and use it in GitHub Desktop.
Angular 2 Pipe to map a property : value mapping object into an array of key value pair objects
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'mapToKeyValue'
})
export class MapToKeyValuePipe implements PipeTransform {
transform(obj: Object) {
let modifiedArray = [];
for (let key in obj) {
let value = obj[key];
modifiedArray.push({key, value});
}
return modifiedArray;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment