How Typescript Comparing Two Objects?
I have one class called tax. export class tax { private _id: string; private _name: string; private _percentage: number;` constructor(id: strin
Solution 1:
You're comparing two different instances of the same class. Even though the values are the same within the instance, they're two completely separate entities.
For example, if we were to have a People
class with a single attribute name
. Even if there are two people in the world called John Smith
, they're two completely separate people.
Each instance has its own unique identifier.
If you want to check if two taxes have the exact same values, you could check them one by one.
console.log(a1.getId() === a2.getId() && a1.getName() === a2.getName() && a1.getPercentage() === a2.getPercentage()) // true
More information about comparing objects can be found here
Post a Comment for "How Typescript Comparing Two Objects?"