I have two objects.
one is defaultValue object that not gonna be changed and the another is comparedValue that can be changed.
const defaultValues = {
adminProfile: "Option 1",
channel: {id: 0, name: ''},
datetime: moment().format("yyyy-MM-DDTHH:mm:ssz"),
memo: '',
phoneNumber: 'none',
register: 'yes',
source: {id: 0, name: ''},
starred: false,
studio: 'common',
subject: {id: 0, name: ''},
}
const comparedValues = {
adminProfile: "Option 1",
channel: {id: 0, name: ''},
datetime: moment().format("yyyy-MM-DDTHH:mm:ssz"),
memo: '',
phoneNumber: 'none',
register: 'yes',
source: {id: 0, name: ''},
starred: false,
studio: 'common',
subject: {id: 0, name: ''},
}
If one of value of property is different than another, function returns false.
Here is the code that I wrote
const validation = (comparedValues) => {
return Object.keys(defaultValues).some(value => {
if (comparedValues.hasOwnProperty(value)) {
if (typeof comparedValues[value] === 'object') {
comparedValues[value].id === defaultValues[value].id
}
comparedValues[value] === defaultValues[value]
}
})
};
However this function always return true, how to make function compares two objects and other values one by one and returns false when it catches difference?
return.some()