1function pick (obj: { [key: string]: any }, props: string[] | string) {
2 const propsArray = Array.isArray(props) ? props : props.split(' ')
3 var picked: {
4 [key: string]: any
5 } = {};
6
7 propsArray.forEach(function(prop) {
8 picked[prop] = obj[prop];
9 });
10
11 return picked
12};
1const object = { a: 5, b: 6, c: 7 };
2const picked = (({ a, c }) => ({ a, c }))(object);
3
4console.log(picked); // { a: 5, c: 7 }
1const object = { a: 5, b: 6, c: 7 };const subset = (({ a, c }) => ({ a, c }))(object);console.log(subset); // { a: 5, c: 7 }