I am trying to test the array.flat method inside Visual Studio code using node js from the mand line. When I run the code i get:
"TypeError: arr.flat is not a function"
I have ran the code in chrome and am able to get the desired result (a flattened array)
Note: Even after updating node js to the latest version, it is still not working.
var arr1 = [1, 2, [3, 4]];
arr1.flat();
console.log(arr1)
I am trying to test the array.flat method inside Visual Studio code using node js from the mand line. When I run the code i get:
"TypeError: arr.flat is not a function"
I have ran the code in chrome and am able to get the desired result (a flattened array)
Note: Even after updating node js to the latest version, it is still not working.
var arr1 = [1, 2, [3, 4]];
arr1.flat();
console.log(arr1)
Share
Improve this question
asked Aug 23, 2019 at 3:21
Tyler MoralesTyler Morales
1,8586 gold badges30 silver badges69 bronze badges
4
-
2
.flat()
creates a new array and returns it. It does not modify the source array. – Pointy Commented Aug 23, 2019 at 3:25 - 2 Possible duplicate of .flat() is not a function, what's wrong? – Monarth Sarvaiya Commented Aug 23, 2019 at 3:32
- When you say you updated Node to the latest version, which version was that? – Ry- ♦ Commented Aug 23, 2019 at 4:54
- @Ry- Node version10.16.3 – Tyler Morales Commented Aug 23, 2019 at 13:21
1 Answer
Reset to default 10Only NodeJS version 11 and above support this method. Please note that the current LTS Node version is only at 10.16.3, which does not support this.
Check the patibility table.
To check what version use this:
node --version
If you Node version is below 11, you will need to upgrade it to use it.
Note
Node versions that use odd number major versions (i.e., v11.x.x, v13.x.x) are generally perceived as a test version and should not be used for production applications. Use even number major versions (i.e., v10.x.x, v12.x.x) instead.