* Moves the nested keys of a specified key in an object to the root of the object. * * @param {Object} obj The object to modify. * @param {String} key The key whose nested keys will be moved to root. * @returns {Object} The modified object, or the original object if no modification happe
(obj, key)
| 464 | * // Output: { a: 1, e: 4, c: 2, d: 3 } |
| 465 | */ |
| 466 | static addNestedKeysToRoot(obj, key) { |
| 467 | if (obj[key] && typeof obj[key] === 'object') { |
| 468 | // Add nested keys to root |
| 469 | Object.assign(obj, { ...obj[key] }); |
| 470 | // Delete original nested key |
| 471 | delete obj[key]; |
| 472 | } |
| 473 | return obj; |
| 474 | } |
| 475 | |
| 476 | /** |
| 477 | * Encodes a string to be used in a URL. |