Advertisement
Guest User

Untitled

a guest
Aug 25th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.35 KB | None | 0 0
  1. function isObject(o) {
  2. return Object.prototype.toString.call(o) === '[object Object]';
  3. }
  4.  
  5. function deepClone(data) {
  6. if (Array.isArray(data)) {
  7. return data.map(deepClone);
  8. } else if (isObject(data)) {
  9. return Object.keys(data).reduce(function(o, k) {
  10. o[k] = deepClone(data[k]);
  11. return o;
  12. }, {});
  13. } else {
  14. return data;
  15. }
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement