I have an array of objects containing different server configurations. For example, objects with attributes for URL, Username, Password etc... I want to prevent the user from entering duplicate server configuration objects in this array of objects. How can I do that?
I am not looking for reference checks using "===". It only checks for the references. I need to compare all the attributes of each object and push only when the configuration does not exist in the array.
Array:
[{
"url": "test.com",
"username": "Rishabh",
"apiKeys": "test",
"jobName": "testJob"
}, {
"url": "test2.com",
"username": "Rishabh2",
"apiKeys": "test",
"jobName": "testJob"
}]
Input:
{
"url": "test2.com",
"username": "Rishabh2",
"apiKeys": "test",
"jobName": "testJob"
}
For the above array and input, the result should be negative (i.e. duplicate entry).
This question, How to determine if object is in array, doesn't answer my question. It clearly says that "car1 and car4 contain the same data but are different instances they should be tested as not equal." I want the opposite. If 2 objects contain the same data, they should be considered equal. Also, I want to compare the property names as well as values.