Extend Object javascript

object,tipjs

Extend Object javascript

var obj1 = {'a': 'obj2','b':'2'};
var obj2 = {name: 'obj3'};
function extend() {
    var length = arguments.length;
    var target = arguments[0] || {};
    if (typeof target!="object" && typeof target != "function") {
        target = {};
    }
    if (length == 1) {
        target = this;
        i--;
    }
    for (var i = 1; i < length; i++) { 
        var source = arguments[i]; 
        for (var key in source) { 
            if (Object.prototype.hasOwnProperty.call(source, key)) { 
                target[key] = source[key]; 
            } 
        } 
    }
    return target; 
}
console.log(extend(obj1,obj2)); //'a': 'obj2','b':'2', name: 'obj3'}

Có thể bạn đã miss một số snippets code

Remove array of objects from another array of objects

Remove array of objects from another array of objects

Copy a string to the clipboard

Copy a string to the clipboard. Only works as a result of user action (i.e. inside a click event listener).

await axios get

await axios get

Random Number javascript

Random Number javascript

Callback in javascript

Callback in javascript