October 5, 2022

Robotic Notes

All technology News


1 min read

Working with arrays is an essential skill in any programming language, especially JavaScript, as we continue to rely on external data APIs. JavaScript has added methods like find and `findIndex recently, but one syntax I love from languages ​​like Python is retrieving values ​​by negative indexes.

When you want to get the value of the last item in an array, you end up with an archaic expression:

const arr = ["zero", "one", "two", "three"];
const last = arr[arr.length - 1];

You could use pop but that modifies the array. 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 shorthand syntax!

Website performance monitoring
Website performance monitoring
Website performance monitoring
Website performance monitoring
  • Serving Fonts from CDN

    Serving Fonts from CDN

    For maximum performance, we all know we must put our assets on CDN (another domain). Along with those assets are custom web fonts. Unfortunately custom web fonts via CDN (or any cross-domain font request) don’t work in Firefox or Internet Explorer (correctly so, by spec) though …

  • From Webcam to Animated GIF: the Secret Behind chat.meatspac.es!
  • Using TogetherJS
  • Flext: MooTools Auto-Growing Textrea Plugin

Source link