function utilityJson(obj, obj2, name, type) {
  if (type === "b") { // return true if Property named name exists > getObjectByStringJSON(obj, [], "PropertyName to find in object", "b")
    Object.byString = function (o, n) {
      n = n.replace(/^\./, '');
      if (n in o) return true;
      else return false;
    }
    return Object.byString(obj, name);
  }
  else if (type === "s") { // return property name as string of arrays > getObjectByStringJSON(obj, [], "", "s")
    const prop = Object.keys(obj);
    var propNames = [];
    prop.forEach(function (k) {
      propNames.push(k);
    });
    return propNames;
  }
  else { // a  // append new properties to existing DS > getObjectByStringJSON(obj old, obj2 new (to be appended in old), "", "a")
    for (var i = 0; i < obj2.length; i++) {
      Object.assign(obj[i], obj2[i]); // common property will be replaced with latest value
    }
    return obj;
  }
}
 
Comments
Post a Comment