Last active
November 3, 2016 09:59
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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