objectOneProperties.forEach((property, index) => { let propName = objectOneProperties[index]; if (objectOne[propName] == objectTwo[propName]) { isEqual = true; } else { isEqual = false; } });
This returns true if the last property values are equal, regardless of the other values.
true
It would make more sense to me if you use a regular for loop and break on false:
let isEqual = true; for(let propName of objectOneProperties) { if(objectOne[propName] != objectTwo[propName]) { isEqual = false; break; } }
Thanks for the tip, but as you already know if it ain't broke don't touch it 😉, but honestly I didn't though about it thanks 👍
If you change personTwo to
personTwo
let personTwo = { name: "james", lastName: "Owen", };
Then you still get true, but the properties are not all the same. Is that what you intended?
No your feedbacks are priceless thanks a lot, I've changed it thanks
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
This returns
true
if the last property values are equal, regardless of the other values.It would make more sense to me if you use a regular for loop and break on false:
Thanks for the tip, but as you already know if it ain't broke don't touch it 😉, but honestly I didn't though about it thanks 👍
If you change
personTwo
toThen you still get
true
, but the properties are not all the same. Is that what you intended?No your feedbacks are priceless thanks a lot, I've changed it thanks