forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPick.js
More file actions
38 lines (32 loc) · 1.01 KB
/
Copy pathPick.js
File metadata and controls
38 lines (32 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2020 Photon Storm Ltd.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
var HasValue = require('./HasValue');
/**
* Returns a new object that only contains the `keys` that were found on the object provided.
* If no `keys` are found, an empty object is returned.
*
* @function Phaser.Utils.Objects.Pick
* @since 3.18.0
*
* @param {object} object - The object to pick the provided keys from.
* @param {array} keys - An array of properties to retrieve from the provided object.
*
* @return {object} A new object that only contains the `keys` that were found on the provided object. If no `keys` were found, an empty object will be returned.
*/
var Pick = function (object, keys)
{
var obj = {};
for (var i = 0; i < keys.length; i++)
{
var key = keys[i];
if (HasValue(object, key))
{
obj[key] = object[key];
}
}
return obj;
};
module.exports = Pick;