Array

const arr=[2,4,5,8,9,7,7,5,8,9]
arr.at(2);
please why is this not working

Hi. Perhaps you should elaborate your question more. What do you mean by “Why this is not working?” Do you mean you can’t see an output when there is no error, or it throws an error when you run the code?

I suspect that .at doesn’t work for arrays in some of Codecademy’s stuff because it used an older version of JavaScript for some stuff [on Codecademy’s severs].

so you might have to do
arr[2]
instead of
arr.at(2)

or maybe
console.log(arr[2]);
if you want output in the console.

1 Like

it outputs an error
I’m unable to edit the original question

You can refer to this for further review on the .at() method. Note that this method is marked as Experimental.

The most likely reason could be what @janbazant1107978602 mentioned in his reply. Another reason (if you’re testing outside Codecademy) could be that your browser does not support this function yet. However, as I have tested, it works with Google Chrome and Mozilla Firefox.

Hope this helped!

1 Like

I don’t know that it comes down to the LE being the culprit, it may well be the SCT, itself. If it predates the introduction of this method, then the author would not be expecting it. The JavaScript we are running is in our browser.

where LE and SCT is?

LE   =>  Learning Environment

SCT  =>  Submission Correctness Test
1 Like