The typeerror: reduce is not a function in JavaScript occurs when we call reduce() method on a value that is not an array or you are using an old browser that doesn’t support this method. Following the explanation below to understand better.
What causes the error “Type Error: reduce is not a function“?
Call reduce() on a value other than an array
const num = 3; const result = num.reduce((sum, elem) => sum + elem, 0); console.log(result);
Output
Here, we executed the method on a number that caused the error.
Using an old browser that does not support the reduce() method
How to solve this error?
Call reduce() method on a valid array
let numArr = [1, 23, 14, -23]; // Loop through an array of the number to find the sum of all elements let result = numArr.reduce((sum, ele) => sum + ele, 0); console.log(result);
Output
15
Before executing, check whether a variable is an array by using Array.isArray() method or instanceof operator
let num = 3; let numArr = [1, 23, 14, -23]; // Check the num variable is not an array, therefore if statement will be executed if (Array.isArray(num)) { let result = num.reduce((sum, ele) => sum + ele, 0); console.log(result); } else { console.log("num variable is not an array"); } // Check the numArr variable is an array, therefore if statement will be executed if (Array.isArray(numArr)) { let result = numArr.reduce((sum, ele) => sum + ele, 0); console.log(result); } else { console.log("numArr variable is not an array"); }
Output
"num variable is not an array"
15
The Array.isArray() will check whether the passed value is an array. It returns a boolean value. In this case, the num variable is not an array, but the numArr variable is an array.
let num = 3; let numArr = [1, 23, 14, -23]; // Check the num variable is not an array, therefore if statement will be executed if (num instanceof Array) { let result = num.reduce((sum, ele) => sum + ele, 0); console.log(result); } else { console.log("num variable is not an array"); } // Check the numArr variable is an array, therefore if statement will be executed if (numArr instanceof Array) { let result = numArr.reduce((sum, ele) => sum + ele, 0); console.log(result); } else { console.log("num variable is not an array"); }
Output
"num variable is not an array"
15
The instanceof operator checked if a constructor’s prototype exists on the object’s prototype chain. The operator returns a boolean value.
If you want to call the reduce() method on an object. You can convert all keys of an object to an array, then loop through it to get values.
let userObj = { name: "John", age: 18 }; let keysArr = Object.keys(userObj); // ["name","age"] // Loop through an array of object keys. With each key, get the corresponding value, then add it to the resulting string let result = keysArr.reduce((value, key) => value + userObj[key] + " ", ""); console.log(result.trim());
Output
"John 18"
You can learn more about how to get an object’s values as array in Javascript.
Check browser compatibility
You can use the caniuse website to check whether the browser’s current version supports the reduce() method. The image below shows browser compatibility with the reduce() method. Notice that:
- Red color: not supported yet.
- Green color: supported.
- Gray color: unknown.
Summary
The error “TypeError: reduce is not a function” in JavaScript frequently occurs when working with arrays. Make sure you execute the reduce() method on a valid array or using the browser that supports it. If you have any questions or comments, please feel free to leave us a message below.

My name is Otis Manders, and I like programming and sharing my skills. Java, Javascript, and others are some of my strong programming languages that I can share with everyone. In addition, I have created applications with the React library, HTML, CSS, and Javascript.
Name of the university: UTC
Programming Languages: C, C++,Java, Javascript, Html, Css