push() won't work as expected in reduce()

后端 未结 4 512
悲&欢浪女
悲&欢浪女 2021-01-17 08:48

Why doesn\'t a.push(b) work in my Array.reduce()? a=a.push(b) where b is a string, turns a to an integer.?!



        
4条回答
  •  孤独总比滥情好
    2021-01-17 09:23

    The push() returns the new length. You can use ES2015 spread syntax:

    
    var winner = objKeys.reduce((a, b)=> {
        a = (frequency[b] === highestVal)? [...a, b] : a;
        return a
    }, []);
    
    

提交回复
热议问题