Use the existence of an externally fetched value to determine whether the corresponding value is displayed in the upcoming loop.

problem description

I"m going to loop through this array now

{
  father: "",
  mother: "",
  husband: "",
  wife: "",
  brother: "",
  sister: "",
  son: "",
  daughter: "",
};

I want to get the values of father, mother, husband and wife from the outside to decide whether to display father, mother, husband and wife in the loop. How to achieve this?
for example, if I get an empty value of my father externally, then show my father"s output in the loop

the environmental background of the problems and what methods you have tried

related codes

/ / Please paste the code text below (do not replace the code with pictures)

function getMenu(d) {
        //
        var father = {};
        function getFather(d) {
          let arr = data;
          return arr.find(function (item, index, arr) {
            if (item.people.id == d.uid) {
              return father
            }
          })
        };
        //
        var mother = {};
        function getMother(d) {
          var fatherId = getFather(d).rel.father.id;
          let arr = data;
          return arr.find(function (item, index, arr) {
            if (item.rel.husband) {
              if (item.rel.husband.id == fatherId) {
                return mother;
              }
            }
          })
        };
        //alert(mother + "");
        //alert(father + "");
        //
        var relAliasData = {
  father: "",
  mother: "",
  husband: "",
  wife: "",
  brother: "",
  sister: "",
  son: "",
  daughter: "",
};
        let a = "";
        let obj = relAliasData;
        let newObj = d;
        for (var m in obj) {
          if (!d[m]) {
            a += ":" + obj[m]
          }
        }
        alert(a)
      }

what result do you expect? What is the error message actually seen?

when mom and dad are already equivalent in the data, the output of mom and dad in the circular array is not allowed to be displayed

Jun.06,2021

is not very clear about your requirements, but the guess is this:
external value takes external value, and no value takes default value.

/ / judging the type of object, use
/ / shallow copy to copy source Baidu, too lazy to write
var util = (function () {

var class2type = {};
["Null", "Undefined", "Number", "Boolean", "String", "Object", "Function", "Array", "RegExp", "Date"].forEach(function (item) {
    class2type["[object " + item + "]"] = item.toLowerCase();
})

function isType(obj, type) {
    return getType(obj) === type;
}

function getType(obj) {
    return class2type[Object.prototype.toString.call(obj)] || "object";
}

return {
    isType: isType,
    getType: getType
}

}) ();
/ / object deep, shallow copy
function copy (obj, deep) {

if (obj === null || typeof obj !== "object") {
    return obj;
}
var i, target = this.util.isType(obj, "array") ? [] : {}, value, valueType;
for (i in obj) {
    value = obj[i];
    valueType = this.util.getType(value);
    if (deep && (valueType === "array" || valueType === "object")) {
        target[i] = this.copy(value);
    } else {
        target[i] = value;
    }
}
return target;

}

var defaultData = {

  father: '',
  mother: '',
  husband: '',
  wife: '',
  brother: '',
  sister: '',
  son: '',
  daughter: ''
},
out = {
  father: '22',
  brother: '223'
},
defaultCopy = copy(defaultData, true); //

for (var key in out) {
defaultCopy [key] = out [key];
}
console.log (defaultCopy);
/ / the data in the defaultCopy is the data you want

Menu