array.reduce不是reactjs中的函数

array.reduce不是reactjs中的函数,reactjs,Reactjs,我正在根据日期筛选任务列表。当我给出自定义日期时,它应该显示任务列表。所有API部分都工作得很好 groupBy = (array, key) => { // Return the end result return array.reduce((result, currentValue) => { // If an array already present for key, push it to the array. Else create an a

我正在根据日期筛选任务列表。当我给出自定义日期时,它应该显示任务列表。所有API部分都工作得很好

groupBy = (array, key) => {
    // Return the end result
    return array.reduce((result, currentValue) => {
        // If an array already present for key, push it to the array. Else create an array and push the object
        (result[currentValue[key]] = result[currentValue[key]] || []).push(
            currentValue
        );
        // Return the current iteration `result` value, this will be taken as next iteration `result` value and accumulate
        return result;
    }, {}); // empty object is the initial value for result object
};
我得到的错误是:'

TypeError: array.reduce is not a function

因为我是新手,所以我不知道。有什么建议吗?

您没有向函数传递数组。最好的猜测是你经过一个物体。确保
array
实际上是一个arrayAdd
控制台。在
groupBy
方法的第一行中记录(array)
,以了解
array
所包含的值。如果您更新问题以包括调用
groupBy
的内容以及传递的内容,以及如何在组件生命周期中实例化和更新这些对象,我们可以更好地提供帮助。现在我们需要更多调试详细信息。请添加更多信息。