Manipulating information is core to any programming language. JavaScript isn’t any exception, particularly as JSON has token over as a primary information supply format. One such information manipulation is reversing arrays. It’s possible you’ll need to reverse an array to indicate most up-to-date transactions, or easy alphabetic sorting.
Reversing arrays with JavaScript initially was completed by way of reverse
however that will mutate the unique array:
// First worth: const arr = ['hi', 'low', 'ahhh']; // Reverse it with out reassigning: arr.reverse(); // Worth: arr (3) ['ahhh', 'low', 'hi']
Modifying the unique array is a legacy methodology. To keep away from this mutation, we would copy the array after which reverse it:
const reversed = [...arr].reverse();
As of late we are able to use toReversed
to keep away from mutating the unique array:
const arr = ['hi', 'low', 'ahhh']; const reversed = arr.toReversed(); // (3) ['ahhh', 'low', 'hi']; arr; // ['hi', 'low', 'ahhh']
Avoiding mutation of information objects is extremely essential in a programming language like JavaScript the place object references are significant.
Serving Fonts from CDN
For optimum efficiency, everyone knows we should put our property on CDN (one other area). Together with these property are customized net fonts. Sadly customized net fonts by way of CDN (or any cross-domain font request) do not work in Firefox or Web Explorer (accurately so, by spec) although…
Google Font API
Google not too long ago debuted a brand new net service referred to as the Font API. Google’s Font API gives builders a method by which they might rapidly and painlessly add customized fonts to their web site. Let’s take a fast take a look at the methods by which the Google Font…
Introducing LazyLoad 2.0
Whereas enhancements in browsers means extra cool APIs for us to play with, it additionally means we have to keep present code. With Firefox 4’s launch got here information that my MooTools LazyLoad plugin was not intercepting picture loading — the pictures had been loading no matter…