diff --git a/README.md b/README.md index a0a9f6772..20d665275 100644 --- a/README.md +++ b/README.md @@ -6123,7 +6123,7 @@ const deepClone = obj => { Object.keys(clone).forEach( key => (clone[key] = typeof obj[key] === 'object' ? deepClone(obj[key]) : obj[key]) ); - return clone; + return Array.isArray(obj) ? Array.from(clone) : clone; }; ``` diff --git a/docs/object.html b/docs/object.html index 7dcda1937..d3be7ea53 100644 --- a/docs/object.html +++ b/docs/object.html @@ -101,7 +101,7 @@ Object.keys(clone).forEach( key => (clone[key] = typeof obj[key] === 'object' ? deepClone(obj[key]) : obj[key]) ); - return clone; + return Array.isArray(obj) ? Array.from(clone) : clone; };
const a = { foo: 'bar', obj: { a: 1, b: 2 } };
 const b = deepClone(a); // a !== b, a.obj !== b.obj
diff --git a/snippets/deepClone.md b/snippets/deepClone.md
index de791ee7e..0b9e19497 100644
--- a/snippets/deepClone.md
+++ b/snippets/deepClone.md
@@ -7,8 +7,6 @@ Use `Object.assign()` and an empty object (`{}`) to create a shallow clone of th
 Use `Object.keys()` and `Array.forEach()` to determine which key-value pairs need to be deep cloned.
 
 ```js
-
-
 const deepClone = obj => {
   let clone = Object.assign({}, obj);
   Object.keys(clone).forEach(
@@ -19,10 +17,6 @@ const deepClone = obj => {
 ```
 
 ```js
-
-
-
-
 const a = { foo: 'bar', obj: { a: 1, b: 2 } };
 const b = deepClone(a); // a !== b, a.obj !== b.obj
 ```