我有以下哈希键:JavaScript中定义的值对。将以下值附加到哈希末尾的最有效方法是什么:
Title: 'Title5', Description: 'Description5', Status: 'Status5', Complete: 'Complete5'
代码:
data = {
d : {
results: [
{ Title: 'Title1', Description: 'Description1', Status: 'Status1', Complete: 'Complete1' },
{ Title: 'Title2', Description: 'Description2', Status: 'Status2', Complete: 'Complete2' },
{ Title: 'Title3', Description: 'Description3', Status: 'Status3', Complete: 'Complete3' },
{ Title: 'Title4', Description: 'Description4', Status: 'Status4', Complete: 'Complete4' }
]
}
};
答案 0 :(得分:1)
data.d.results.push({Title: 'Title5', Description: 'Description5', Status: 'Status5', Complete: 'Complete5'});
答案 1 :(得分:0)
只需使用push
。
var newItem = {Title: 'Title5', Description: 'Description5', Status: 'Status5', Complete: 'Complete5'}
data.d.results.push(newItem)