Working with arrays is an important ability in any programming language, particularly JavaScript, as we proceed to depend on exterior knowledge APIs. JavaScript has added strategies like discover
and `findIndex
not too long ago, however one syntax I like from languages like Python is retrieving values by unfavourable indexes.
Once you wish to get the worth of the final merchandise in an array, you find yourself with an archaic expression:
const arr = ["zero", "one", "two", "three"]; const final = arr[arr.length - 1];
You can use pop
however that modifies the array. As an alternative you should use at
and an index, even a unfavourable index, to retrieve values:
const arr = ["zero", "one", "two", "three"]; arr.at(-1); // "three" arr.at(-2); // "two" arr.at(0); // "zero"
at
is a little or no recognized operate however helpful, if just for the shorthand syntax!
An Interview with Eric Meyer
Your early CSS books had been instrumental in pushing my love for entrance finish applied sciences. What was it about CSS that you simply fell in love with and drove you to jot down about it? At first blush, it was the simplicity of it as in comparison with the table-and-spacer…
MooTools 1.3 Browser Object
MooTools 1.3 was simply launched and one of many massive additions is the Browser object. The Browser object may be very useful in that not solely do you get details about browser kind and browser variations, you’ll be able to acquire details about the consumer’s OS, browser plugins, and…
CSS Vertical Centering
Entrance-end creating is gorgeous, and it is getting prettier by the day. These days we received so many ideas, methodologies, good practices and whatnot to make our work stand out from the remaining. Javascript (together with its numerous third occasion libraries) and CSS have grown so massive, serving to…
Source link