Check whether an Object contains a specific value in any of its array

How to find if an object has a value? My Object looks like below: I have to loop through the object array and check if an array has “SPOUSE” in its value. if exist set a flag spouseExits = …

How to filter array of objects where object has property tagId or keywordId in JS?

I have an array of objects and I am trying to filter it by checking if the object has property tagId or keywordId. I thought about this but not sure if it’s the correct way. const filteredProducts = …

Getting error while referencing the type as index

I have an array of objects with the following structure I need to take each key within each object inside array and form an array out of it. Basically grouping based on the key present in all the objects.If the object has no “values” it should return 0 across the val1,val2,val3. Here I am passing an string, that will be used inside reduce.I am getting this error any cannot be used as index whenever I pass in a dynamically string that will be used inside a reduce function whenever typescript is enabled. The code works just fine, but after I

How to get a property with get/set to serialize with JSON.stringify()

I have the following scenario: I was hoping that I can somehow set a toJSON method on the property “x” in the defineProperty call, but that didn’t work. Any help would be appreciated. Answer This is what worked for me: Note test is not a prototype definition and enumerable has to be set to true. I tested the above working version in IE9, FF 11 and Chrome 18 – all three gave expected results.