Javascript, arrays

Hey everyone

I’ve ran into an issue with the “Looking for more ways to practice” section in the introduction to JS - Arrays lesson.

I am asked to - “Take all the elements in an array and make a string.”
My array is nested and I understood that it required flattening to first convert it to a single array with .flat();
However, when I attempt to use this method I get an error that reads - “TypeError: myNumbers.flat is not a function”.

Can anyone explain what I might be doing wrong?

https://www.codecademy.com/courses/introduction-to-javascript/lessons/arrays/exercises/review-arrays

That’s beacuse .flat() is not a default function for now, so it’s not implemented in the browser

I understand that the .flat() method is a relatively recent addition to JavaScript, introduced in ES2019. However, the .flat() method is supported by my browser (FireFox).

I did a little research and discovered Cocecademy also supports the use of .flat() in the learning enviroment, so I’m a bit confused.

Any other suggestions as to why I get this error message?


So that’s the problem, they use an older version. The flat() method works on version 11, they’re using the version 7. But u can still try to do this exercise in the workspace of codecademy, in the main page. In the workspace their using the newest version

2 Likes