Working with arrays is an essential skill in any programming language, especially JavaScript, as we continue to rely on external data APIs. JavaScript added methods like find
And`findIndex
Recently, but one syntax I like from languages like Python is retrieving values by negative indexes.
When you want to get the value of the last item in the array, you get an archaic expression:
const arr = ["zero", "one", "two", "three"]; const last = arr[arr.length - 1];
You can use pop
But that changes the lineup. Instead you can use at
And an index, even a negative 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 very little known function but useful, if only for the syntax of the abbreviation!
Create a CSS cube
CSS cubes really showcase what CSS has become over the years, evolving from simple color and dimension guidelines to a language capable of creating deep, creative visuals. Add animation and you have something really neat. Unfortunately every CSS cube tutorial I read is a bit …
Be Dev Dad
I get asked a lot of questions every day but I’m always surprised that they are rarely questions about code or even technology – a lot of the questions I get are more about non-developer things like how my office is, what software I use, and often …
Create spaces with Flexbox
I was one of the biggest fans of flexbox before it came, but due to a shuffle in the Mozilla, I never had a chance to use it in any practice project; So, flexbox still seems like a bit of a mystery to me. It is very…
prefers-color-scheme: CSS Media Query
One feature of device and app that I learned to appreciate is the ability to switch between light and dark mode. If you have ever done coding or reading late at night, you know how amazing a dark subject can be to prevent eye strain and the resulting headaches.
Source