JavaScript附加密钥:值对哈希值

时间:2017-03-06 09:26:50

标签: javascript hash

我有以下哈希键: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' }
        ]
    }
};

2 个答案:

答案 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)