For example I have this dataInput json:
dataInput= [
{text: 'text1'},
{text: 'text2'},
{text: 'text3'}
];
and I want to compare it with:
dataInputUpdated= [
{text: 'text1', info: 'something'},
{text: 'text2'},
{text: 'text3'}
];
How to compare between them with Typescript? Is there any equal method? This is array of objects, so I wanna know its not equal on any change.
You can use JSON.stringify method to do the comparison. Here is a sample:
let dataInput= [
{text: 'text1'},
{text: 'text2'},
{text: 'text3'}
];
let dataInputUpdated= [
{text: 'text1', info: 'something'},
{text: 'text2'},
{text: 'text3'}
];
let areSame: boolean = JSON.stringify(dataInput) === JSON.stringify(dataInputUpdated);
alert(areSame); // returns false
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With