how to find duplicate item from array using multiple object keys in angular or javascript

 how to find duplicate item from array using multiple object keys


There is a way to find based of multiple key find duplicate records in angular or javascript

 
getDuplicate(itemskeys) {
        let duplicates = [];
        for (let i = 0i < items.lengthi++) {
            let matchkey = 0;
            for (let j = 0j < keys.lengthj++) {
                if ((i < (items.length - 1)) && items[i + 1][keys[j]].toLowerCase() === items[i][keys[j]].toLowerCase()) {
                    matchkey++;
                }
            }
            if (matchkey === keys) {
                duplicates.push(items[i]);
            }
        }
        return duplicates;
    }

Example:
const duplicatethis.getDuplicate(CounterParty, ['OperatorId''TCID']);

















angular form control and formarray sort using perticular key asc and desc

 angular form control and formarray sort using perticular key asc and desc





there are three diffrent way to sort data form control and form array in angular 

1). FormArray sorting
   
 sortFormArray(arrayanyargstype = 'asc') {
        if (array !== undefined) {
            return array.controls.sort((aanybany=> {
                const aValue = a.controls[args].value;
                const bValue = b.controls[args].value;
                let condition1 = aValue > bValue;
                let condition2 = aValue < bValue;
                if (type === 'asc') {
                    condition1 = aValue < bValue;
                    condition2 = aValue > bValue;
                }
                if (condition1) {
                    return -1;
                } else if (condition2) {
                    return 1;
                } else {
                    return 0;
                }
            });
        }
        return array;
    }

Example:
const Address= FormArray();
sortFormArray(Address'CountryID','asc');


2).sort list data  getsort(List?) {
        if (List) {
            return List.sort((ab=> (a > b) ? 1 : -1);
        } else { return null; }
    }

Example:

getsort(this.items);
getsort(this.items);



3).sorting using lodash    getsortNew(List?,key:[],type:[]) {
        if (List) {
            return lodash.sortBy(List, key,type);
        } else { return null; }
    }

Example:
getsortNew(this.items,['CountryID'],[asc]);
getsortNew(this.items,['CountryID'],[desc]);













how to convert json to xml in angular

 how to convert json to xml in angular



var obj={'name':raj,'address':{'add':'skg'}}


 JsontoXML(obj) {
    var xml = '';
    for (var prop in obj) {
      xml += obj[propinstanceof Array ? '' : "<" + prop + ">";
      if (obj[propinstanceof Array) {
        for (var array in obj[prop]) {
          xml += "<" + prop + ">";
          xml += this.JsontoXML(new Object(obj[prop][array]));
          xml += "</" + prop + ">";
        }
      } else if (typeof obj[prop] == "object") {
        xml += this.JsontoXML(new Object(obj[prop]));
      } else {
        xml += obj[prop];
      }
      xml += obj[propinstanceof Array ? '' : "</" + prop + ">";
    }
    var xml = xml.replace(/<\/?[0-9]{1,}>/g'');
    return xml
  }

and finally download json into file 

 downloadXMLFile(xmltradeID) {
    const blob = new Blob([xml], { type: 'application/xml;charset=UTF-8' });
    FileSaver.saveAs(blobtradeID + '.xml');

  }




Featured Post

how to find duplicate item from array using multiple object keys in angular or javascript

 how to find duplicate item from array using multiple object keys There is a way to find based of multiple key find duplicate records in ang...

Popular Posts