Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function isObject(o) {
- return Object.prototype.toString.call(o) === '[object Object]';
- }
- function deepClone(data) {
- if (Array.isArray(data)) {
- return data.map(deepClone);
- } else if (isObject(data)) {
- return Object.keys(data).reduce(function(o, k) {
- o[k] = deepClone(data[k]);
- return o;
- }, {});
- } else {
- return data;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement