This is the error message I got:
numbers.sort((a,b) => a - b); ^
TypeError: numbers.sort is not a function
Has anyone else run into this?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Click below to sign up and get $200 of credit to try our products over 60 days!
That error looks like the type that you get when your
numbersvariable is not actually typed as an Array.
For example, if you have some code where the numbers variable was an object or an integer or a string:
You will get
Uncaught TypeError: numbers.sort is not a functionbecause there is no sort function for strings.
But if you check this exact snippet of code:
You should definitely not see any errors.
When you say:
This makes me think you are seeing IDE debugging warnings which could also be due to other problems with the your VS Code and extensions config.
But my first recommendation on debugging would be to check the TYPE of the
numbersvariable just before you call
numbers.sort()and confirm that it is an Array