nonespace
5/30/2018 - 6:02 AM

arr handle tails 0

数组去除最后数组为0的项目采用递归

let arr = [
    {
        "date": "2018-05-15",
        "value": 635
    },
    {
        "date": "2018-05-16",
        "value": 713
    },
    {
        "date": "2018-05-17",
        "value": 599
    },
    {
        "date": "2018-05-18",
        "value": 737
    },
    {
        "date": "2018-05-19",
        "value": 861
    },
    {
        "date": "2018-05-20",
        "value": 1661
    },
    {
        "date": "2018-05-21",
        "value": 706
    },
    {
        "date": "2018-05-22",
        "value": 821
    },
    {
        "date": "2018-05-23",
        "value": 952
    },
    {
        "date": "2018-05-24",
        "value": 0
    },
    {
        "date": "2018-05-25",
        "value": 0
    },
    {
        "date": "2018-05-26",
        "value": 0
    },
    {
        "date": "2018-05-27",
        "value": 0
    },
    {
        "date": "2018-05-28",
        "value": 0
    }
]

function removeItem(arr){
    let a = arr[arr.length - 1]
    if (arr.length == 1 ) {
        return false
    }
    if (a.value == 0){
        arr.splice(arr.length - 1,1)
        return removeItem(arr)
    }
}