showing results for - "how to copy value instead of reference js"
Adrien
31 Jun 2016
1function goclone(source) {
2    if (Object.prototype.toString.call(source) === '[object Array]') {
3        var clone = [];
4        for (var i=0; i<source.length; i++) {
5            clone[i] = goclone(source[i]);
6        }
7        return clone;
8    } else if (typeof(source)=="object") {
9        var clone = {};
10        for (var prop in source) {
11            if (source.hasOwnProperty(prop)) {
12                clone[prop] = goclone(source[prop]);
13            }
14        }
15        return clone;
16    } else {
17        return source;
18    }
19}
20
21var B = goclone(A);
22