I have two objects from the same constructor, they differ the first and second properties, but all the rest match. I want to confirm that in the code.
The JSON.stringify is good to compare whole objects, but not so good with starting from a certain property. I tried creating two variables one for each object, strigifying the first and second properties and adding them together in one string, for each variable.
And THEN I compare the two objects stringifying them by using substring starting from the variables LENGTH like this:
function Car(carname, price, performance, efficiency, offroad, size, twoseat, legroom, trunkspace, electric) {
this.carname = carname; this.price = price; this.performance = performance;
this.efficiency = efficiency; this.offroad = offroad; this.size = size;
this.twoseat = twoseat; this.legroom = legroom; this.trunkspace = trunkspace; this.electric = electric;}
var userParameters = new Car("!", 1, null, true, false, true, false, false, false, false);
var fiat500 = new Car("Fiat 500", 19000, null, true, false, true, false, false, false, false);
var n = JSON.stringify(userParameters.carname) + JSON.stringify(userParameters.price);
var m = JSON.stringify(fiat500.carname) + JSON.stringify(fiat500.price);
var stringCar = JSON.stringify(fiat500);
var stringUser = JSON.stringify(userParameters);
if ((stringCar.substring(n.length)) === (stringUser.substring(m.length))) {
//Do stuff in case equal
}
It looks like it would be the solution, but it doesn't work. Halp