Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to copy value instead of reference js

function goclone(source) {
    if (Object.prototype.toString.call(source) === '[object Array]') {
        var clone = [];
        for (var i=0; i<source.length; i++) {
            clone[i] = goclone(source[i]);
        }
        return clone;
    } else if (typeof(source)=="object") {
        var clone = {};
        for (var prop in source) {
            if (source.hasOwnProperty(prop)) {
                clone[prop] = goclone(source[prop]);
            }
        }
        return clone;
    } else {
        return source;
    }
}

var B = goclone(A);
Comment

PREVIOUS NEXT
Code Example
Javascript :: next js start 
Javascript :: split 2 arrays javascript 
Javascript :: patch request javascript 
Javascript :: if else java 
Javascript :: how to remove class in all siblings javascript 
Javascript :: random coordinates js 
Javascript :: javascript encode base64 
Javascript :: javascript get day 
Javascript :: local database with javascript 
Javascript :: how to find for lable in jquery 
Javascript :: hmac_sha256 node 
Javascript :: axios default baseurl conditional environment 
Javascript :: modal.hide not working 
Javascript :: remove duplicates from array of objects 
Javascript :: regex remove spaces 
Javascript :: how to export a variable in javascript 
Javascript :: create javascript array 
Javascript :: javascript async function 
Javascript :: array filter 
Javascript :: codeigniter 3 if ajax request 
Javascript :: jquery form submit ajax 
Javascript :: js array to csv download 
Javascript :: jquery 1 cdn 
Javascript :: javascript remove duplicates 
Javascript :: js execute string 
Javascript :: javascript document.createElement add function 
Javascript :: scroll to top router link vue 
Javascript :: node express app.listen at specific port & host 
Javascript :: Capitalize the first letter of string using JavaScript 
Javascript :: if text exists in element using javascript 
ADD CONTENT
Topic
Content
Source link
Name
1+1 =