将项目推送到数组

时间:2017-09-05 16:49:34

标签: javascript

var result = {
        "fruits": [
            "Apple",
            "Cherry",
            "Clementine",
            "Honeydew melon",
            "Watermelon",
            "Satsuma"
        ],
        "vegetables": [
            "Pepper",
            "Jerusalem artichoke",
            "Green bean",
            "Fennel",
            "Courgette",
            "Yam"
        ]
    };


    showGetResult(result)
    function showGetResult(result) {

        $.getJSON("../../GetBuilding/26/2",
            function (data) {

                $.each(data, function (key, val) {

                    result.fruits.push("some value");

                });
            }); 
    }

有一个数组有类别和catogory项目。每次从数据库返回值,我想将此值推送到数组。但我使用以下代码;

data.push({ "fruits": [val.fruitName] });

我得到“推送不是功能”错误。如何将任何值推送到此数组?

0 个答案:

没有答案