Skip to content

Instantly share code, notes, and snippets.

@flashspys
Last active August 24, 2020 14:07
Show Gist options
  • Save flashspys/23c32246e99652996b42b808f026e3e0 to your computer and use it in GitHub Desktop.
Save flashspys/23c32246e99652996b42b808f026e3e0 to your computer and use it in GitHub Desktop.
MapTo
const handler = {
get: function(_, prop) {
return (obj) => {
return obj.map((entry) => entry[prop]);
}
}
};
const MapTo = new Proxy({}, handler);
// An array of objects.
const objects = [{id: 1, name: "Foo"}, {id: 2, name: "Bar"}, {id: 3, name: "Soo"}, {id: 4, name: "Noo"},]
console.log("huhu", objects |> MapTo.name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment