如何在JQuery中比较两个对象的值是否相等

时间:2016-08-31 11:04:40

标签: jquery json

我有两个地址对象,每个对象中有3个值。 如何在两个对象中测试它的值是否相等?

JSON:

{{1}}

1 个答案:

答案 0 :(得分:0)



var address1 = {"address1": { "city": "bng", "street": "dng", "zipcode": "23421" }};

var address2 = {"address2": { "city": "chn", "street": "as", "zipcode": "5645" }};

var equality = JSON.stringify(address1.address1) != JSON.stringify(address2.address2) ? 'not same' : ' same';

console.log(equality);


var address1 = {"address1": { "city": "bng", "street": "dng", "zipcode": "23421" }};

var address2 = {"address2": { "city": "bng", "street": "dng", "zipcode": "23421" }};

var equality = JSON.stringify(address1.address1) != JSON.stringify(address2.address2) ? 'not same' : ' same';

console.log(equality);