An array is a data structure, which can store a fixed-size collection of elements of the same data type
If you have worked with JavaScript arrays ...
Some comments have been hidden by the post's author - find out more
For further actions, you may consider blocking this person and/or reporting abuse
it is making an error, arr.at is not a function.
This is modern ES6 syntax, you will either need a modern browser/version of node or to use a transpiler like Babel.
This is the currently supported list:
caniuse.com/mdn-javascript_builtin...
perfect
I especially love this feature when combined with optional chain, in TypeScript, e.g.
unknownArr?.at(1) ?? 0
. It makes the code so much cleaner.Beat me to it
well i always do
i always use arr.length-1
arr.pop() ?????
pop() method removes the last element from an array and returns that element. This method changes the length of the array.
Cool, i knew a little about the
pop()
method but now is more clear to me.Here is a small example of this
This would log:
As you can see
'grapes'
now doesn't form part of thefruits
variable but at the same time thepop()
method returns the last item of the array. So clearly, if someone is going to use this method must be aware of this.The destructuring tip here is a good one, but it's not your own. It comes from 30 Seconds of Code -- 30secondsofcode.org/articles/s/js-....
Sharing links to useful articles, tips and content is great, but please don't simply repost other people's work in entirety and without credit. A better approach is to include a short extract from the original article, clearly identify the original author and and include a link to the original material. Something like this:
I found this great tip on 30 Seconds of Code for using destructing to get an array's length, last element.
See the original article at 30secondsofcode.org/articles/s/js-...