We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 78e1a09 commit e6f158fCopy full SHA for e6f158f
src/utils/pick.js
@@ -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