Skip to content

Instantly share code, notes, and snippets.

@JonathanDn
Last active November 3, 2016 09:59
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/272f30368efbeaefded3f353abd97d7f to your computer and use it in GitHub Desktop.
Save JonathanDn/272f30368efbeaefded3f353abd97d7f to your computer and use it in GitHub Desktop.
Angular 2 pipe to map key : value pair object array into object with property value pairs.
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'mapFromKeyValue'
})
export class MapFromKeyValuePipe implements PipeTransform {
transform(objArr) {
console.log('obj array looks like this: ', objArr);
let mappingObject = {};
objArr.forEach((obj) => {
for (let key in obj) {
let value = obj[key];
mappingObject[key] = value;
}
})
return mappingObject;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment