我有两个对象,我需要将一个对象插入第一行的另一个对象中。
我找到了 Javascript 函数splice
,但我不知道如何使用它。
我的代码:
$(document).ready(function() {
var person = {};
person[0] = {};
person[0]['name'] = 'Joy';
person[0]['age'] = '12';
var personAll = {};
personAll[0] = {};
personAll[0]['name'] = 'Vanda';
personAll[0]['age'] = '49';
personAll[1] = {};
personAll[1]['name'] = 'Peter';
personAll[1]['age'] = '12';
var new_object = personAll.splice(0, person);
//I need get this result:
new_object[0]['name'] = 'Joy';
new_object[0]['age'] = '12';
new_object[1]['name'] = 'Vanda';
new_object[1]['age'] = '49';
new_object[2]['name'] = 'Peter';
new_object[2]['age'] = '12';
console.log(new_object);
});
如何修复此代码?