Apply new format to snippets and template
This commit is contained in:
@ -6,11 +6,11 @@ tags: object,recursion,intermediate
|
||||
Creates a deep clone of an object.
|
||||
Clones primitives, arrays and objects, excluding class instances.
|
||||
|
||||
Use recursion.
|
||||
Check if the passed object is `null` and, if so, return `null`.
|
||||
Use `Object.assign()` and an empty object (`{}`) to create a shallow clone of the original.
|
||||
Use `Object.keys()` and `Array.prototype.forEach()` to determine which key-value pairs need to be deep cloned.
|
||||
If the object is an `Array`, set the `clone`'s `length` to that of the original and use `Array.from(clone)` to create a clone.
|
||||
- Use recursion.
|
||||
- Check if the passed object is `null` and, if so, return `null`.
|
||||
- Use `Object.assign()` and an empty object (`{}`) to create a shallow clone of the original.
|
||||
- Use `Object.keys()` and `Array.prototype.forEach()` to determine which key-value pairs need to be deep cloned.
|
||||
- If the object is an `Array`, set the `clone`'s `length` to that of the original and use `Array.from(clone)` to create a clone.
|
||||
|
||||
```js
|
||||
const deepClone = obj => {
|
||||
|
||||
Reference in New Issue
Block a user