To transform your object into a different format where properties become values and values become properties, you can use the following code snippet:
var swappedObject = {};
for (var prop in originalObject) {
if (!(originalObject[prop] in swappedObject)) {
swappedObject[originalObject[prop]] = [];
}
swappedObject[originalObject[prop]].push(prop);
}
After executing this code, your object will look like this:
{
'value1': ['prop1', 'prop3'],
'value2': ['prop2'],
'value3': ['prop4']
}
Subsequently, you can identify any values that have multiple keys associated with them by running the following code:
for (var value in swappedObject) {
if (swappedObject[value].length > 1) {
alert(swappedObject[value].join(', '));
}
}