Created
August 12, 2014 23:49
-
-
Save eddieajau/5f3e289967de60cf7bf9 to your computer and use it in GitHub Desktop.
Extract a column from an array of JavaScript objects.
This file contains hidden or 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
function extractColumn(arr, column) { | |
function reduction(previousValue, currentValue) { | |
previousValue.push(currentValue[column]); | |
return previousValue; | |
} | |
return arr.reduce(reduction, []); | |
} |
function extractColumn(arr, column) {
return arr.map(x => x[column])
}
@Enelar thanks
function extractColumn(arr, column) { return arr.map(x => x[column]) }
ES6 way :)
let extractColumn = (arr, column) => arr.map(x=>x[column]);
@pauloffborba const :P
Awesome function Eddie, thanks a lot!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
9ice one