I would like to know how to compare the object value exists in
the array of objects, then check if it is repeated and return true or false in javascript
for example,
if the object value exists in mode property array object,
then check the valueid property in itemarray has duplicates
conditions to check:
if object has same valueid, mode value is FI/FD(different no duplicates) then return false
if object has same valueid, mode value is SE/SA then return true
if object has same valueid, mode has same/duplicates then return true
var obj={
service: "SE",
sales: "SA",
finance: "FI",
others: "FD"
}
var itemarray=[
{name: "nemo", valueid: "abc", mode: "SE" },
{name: "mike", valueid: "xyz", mode: "FI" },
{name: "jim", valueid: "xyz", mode: "FD" },
{name: "jim", valueid: "mno", mode: "SA" }
]
Expected Result
// same valueid, mode value is FI/FD(different no duplicates)
false
I tried
function checkRepeatedValues(){
const getValues = itemarray.map(elm => elm.valueid);
if (itemArray.length !== new Set(getValues).size) {
return true;
} else {
return false;
}
}