admin管理员组文章数量:1354389
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.
本文标签: javascriptArrayprototypeflat() is not working in command line using Node JSStack Overflow
版权声明:本文标题:javascript - Array.prototype.flat() is not working in command line using Node JS - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743997126a2573195.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论