Blog - wingsico

1
2
3
4
5
6
7
8
9
const pick = (field = "", object = {}) => object[field]
const pluck = (field, array) => array.map(object => pick(field, object))
const deepPluck = (field, array) => array.map(object => deepPick(field, object))
const deepPick = (fields, object = {}) => {
const [first, ...remaining] = fields.split(".")
return (remaining.length) ?
deepPick(remaining.join("."), object[first]) :
object[first]
}