On change delete everything in array and add new values in it

This question already has an answer here:

  • How do I empty an array in JavaScript? 18 answers

  • You need to clear array before pushing new value. Easy way to remove all exisiting values is to set length to 0 :

    saveSelectedValue : function (e) {
        var that = e.data.that,
        selectArray = that.filterSelectedCategories;
        selectArray.length = 0; // clear selectArray array
        selectArray.push($('.posts-filter-cat').val());
        console.log(selectArray);
    },
    
    链接地址: http://www.djcxy.com/p/23956.html

    上一篇: 通过函数参数重置一个数组

    下一篇: 更改时删除数组中的所有内容并在其中添加新值