La modificación de una copia de un objeto JavaScript hace que cambie el objeto original

Estoy copiandomyObj atempMyObj

var tempMyObj = myObj;

tempMyObj.entity es una matriz de objetos Estoy modificandotempMyObj.entity basado en algunas condiciones. El problema es si modificotempMyObj.entity elmyObj.entity También se está modificando.

for (j = 0; j < myObj.length; j++) {
    if (myObj[j].type == "TableShape") {
        var dupEntites = new Array();
        for (i = 0; i < myObj[j].entities.length; i++) {
            if (chk.value != myObj[j].entities[i].id) {
                var obj = {};
                obj.text = myObj[j].entities[i].text;
                obj.id = myObj[j].entities[i].id;
                dupEntites.push(obj);
            }
            else {
                if (chk.checked)
                {
                    var obj = {};
                    obj.text = myObj[j].entities[i].text;
                    obj.id = myObj[j].entities[i].id;
                    dupEntites.push(obj);
                }
            }
        }
        tempMyObj[j].entities = dupEntites;
    }
}

Respuestas a la pregunta(4)

Su respuesta a la pregunta