google+javascriptbanktwitter@js_bankfacebook@jsbankrss@jsbank






Les objets JavaScript: comparer et Clone Ce JavaScript tutorial vous montre un bref aper?u sur les objets JavaScript dans la comparaison et le clonage Vous saurez comment clone objets JavaScript, Assurez- Objet JavaScript copie .


Gratuit iPage hébergement Web pour la première année MOMENT



Si vous êtes toujours à la recherche d'un fournisseur d'hébergement Web fiable avec des tarifs abordables, pourquoi vous ne prenez pas un peu de temps pour essayer iPage, seulement avec $1.89/month, inclus $500+ Crédits supplémentaires gratuites pour le paiement de 24 mois ($45)?

Plus de 1.000.000 de clients + existisng peuvent pas avoir tort, vraiment vous n'êtes pas aussi! Plus important encore, lorsque vous enregistrez l'hébergement web à iPage grâce à notre lien, nous allons être heureux de renvoyer un plein remboursement. C'est génial! Vous devriez essayer iPage hébergement web GRATUITEMENT maintenant! Et contactez-nous pour tout ce que vous devez savoir sur iPage.
Essayez iPage GRATUIT première année MOMENT

Here's a handy way to determine if two JavaScript objects are identical without using a framework like jQuery or MooTools:

var compare_objects = function (obj1, obj2){

 
    var parameter_name;
 
    var compare = function(objA, objB, param){

 
        var param_objA = objA[param],
            param_objB = (typeof objB[param] === "undefined") ? false : objB[param];

 
        switch(typeof objA[param]){
            case "object": return (compare_objects(param_objA, param_objB));

            case "function": return (param_objA.toString() === param_objB.toString());

            default: return (param_objA === param_objB);
        }

 
    };
 
    for(parameter_name in obj1){
        if(typeof obj2[parameter_name] === "undefined" || !compare(obj1, obj2, parameter_name)){

            return false;
        }
    }
 
    for(parameter_name in obj2){

        if(typeof obj1[parameter_name] === "undefined" || !compare(obj1, obj2, parameter_name)){

            return false;
        }        
    }
 
    return true;

 
};

Here's an easy way to clone a JavaScript object:

var clone_object = function (original_obj) {

    var new_obj = {};
    for(var param in original_obj) {

        if(original_obj.hasOwnProperty(param)){
            if(typeof(original_obj[param]) === "object"){

                new_obj[param] = clone_object(original_obj[param]);

            } else {
                new_obj[param] = original_obj[param];

            }
        }
    }
    return new_obj;
};

A real-world example of the two functions:

var object_1 = { fruit: "apple", tree: "dogwood", number: 3 };

var object_2 = { fruit: "apple", tree: "dogwood", number: 3, cartoons: { anime: "robotech", fantasy: "he-man" } };

var object_3 = clone_object(object_2);
 
console.log("objects 1 and 2 match? " +compare_objects(object_1, object_2));

//displays false;
 
console.log("objects 2 and 3 match? " +compare_objects(object_2, object_3));

//displays true

Bear in mind both of these functions are recursive, which means the larger the object, the slower the performance.

iPhoneKer.com
Save up to 630$ when buy new iPhone 15

GateIO.gomymobi.com
Free Airdrops to Claim, Share Up to $150,000 per Project

https://tooly.win
Open tool hub for free to use by any one for every one with hundreds of tools

chatGPTaz.com, chatGPT4.win, chatGPT2.fun, re-chatGPT.com
Talk to ChatGPT by your mother language

Dall-E-OpenAI.com
Generate creative images automatically with AI

AIVideo-App.com
Render creative video automatically with AI

JavaScript par jour


Google Safe Browsing McAfee SiteAdvisor Norton SafeWeb Dr.Web