XeNote/posts/Code/JS/Deep Compare.md
2020-11-28 19:36:28 +03:00

33 lines
823 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

Array ve objeleri kıyaslayıp derin karşılaştırma yapar.
```javascript
export function isEqualObj(a,b){
// Create arrays of property names
var aProps = Object.getOwnPropertyNames(a);
var bProps = Object.getOwnPropertyNames(b);
// If number of properties is different,
// objects are not equivalent
if (aProps.length != bProps.length) {
return false;
}
for (var i = 0; i < aProps.length; i++) {
var propName = aProps[i];
// If values of same property are not equal,
// objects are not equivalent
if (a[propName] !== b[propName]) {
return false;
}
}
// If we made it this far, objects
// are considered equivalent
return true;
}
```
* React kullanırken state değişiminin gerekli olup olmadığına bakılabilir..
#js-code