Skip to content

Commit e6f158f

Browse files
author
utkace
committed
utils: util to create object of passed array
1 parent 78e1a09 commit e6f158f

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/utils/pick.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Returns new object contains only `originalObj`'s properities that exist in `keysToPick`
3+
* @param {Object} originalObj
4+
* @param {Array} keysToPick
5+
*/
6+
export const pick = (originalObj = {}, keysToPick = []) => {
7+
const target = {};
8+
for (let i = 0; i < keysToPick.length; i++) {
9+
const key = keysToPick[i];
10+
11+
if (originalObj.hasOwnProperty(key)) {
12+
target[key] = originalObj[key];
13+
}
14+
}
15+
return target;
16+
}

0 commit comments

Comments
 (0)