locked
How to check whether a stringified array contains object (key-value pairs) of another array in typescript RRS feed

  • Question

  • User-1744141586 posted

    Can anyone suggest me how to check whether a stringified array(set of arrays) contains element of another stringified array(set of arrays)..Below shown if condition doesn't working as required. It is with error..

    this.regService.GetOperators(this.osreq).subscribe((data : any)=>{ this.OSResponseOld = data; this.OldOSResponseInString=StorageService.GetItem("OSResponse"); this.NewOSResponseInString=JSON.stringify(this.OSResponseOld); if(this.OldOSResponseInString.includes(this.NewOSResponseInString)){ this.CombinedResponse=this.OldOSResponseInString; } });

    Tuesday, April 17, 2018 5:11 AM

All replies

  • User753101303 posted

    Hi,

    It seems you are checking if a string (which happens to be a stringified object) is found in an array of objects (or from the name it's not clear if this an object or a stringified array ???).

    IMO stop trying to work on something such as a "stringified array". JSON is a serialization format. Period. IMO make sure to work on ACTUAL objects rather than on "serialized strings" : if(myArray.includes(thisObject)) etc...

    BTW when you post about an error it's best to post the error message you have (or the best English translation you can) so that we can better grasp what happens for now on your side.

    Tuesday, April 17, 2018 3:47 PM