Skip to content
Advertisement

comparing one dictionary with array of dictionary

I want to add or remove a dictionary on the array based on two cases. For example, Let us create a array of dictionary,

JavaScript

Let us consider two cases, Case-1: An input dictionary that has both the same key and value which is in the Result variable.

JavaScript

then the result should be,

JavaScript

Case-2: An input dictionary that has the same key and different value(input1) and vice versa(input2) or both different key and value(input3) which the Result variable array have.

JavaScript

then the result should be,

JavaScript

Thanks in advance

Advertisement

Answer

You could find the index of the given key/value pair and remove this item of the array or push the object to the array.

This approach mutates the array.

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement