我正在尝试在 jQuery 中合并两个对象。
第一个对象:
var rules1 = {
firstname: { required: true, minlength: 3 },
lastname: { required: true, minlength: 3 }
};
第二个对象:
var rules2 = {
test1: { required: true, minlength: 3 },
test2: { required: true, minlength: 3 }
};
我希望结果如下所示:
var merged = {
firstname: { required: true, minlength: 3 },
lastname: { required: true, minlength: 3 },
test1: { required: true, minlength: 3 },
test2: { required: true, minlength: 3 }
};
我还需要知道 PHP 数组的外观如何rules1
,因为该对象将使用json_encode
函数进行转换。