Search
JavaScript: Reverse Arrays
26.6.2023
Manipulating data is core to any programming language. JavaScript is no exception, especially as JSON has token over as a prime data delivery format. One such data manipulation is reversing arrays. You may want to reverse an array to show most recent transactions, or simple alphabetic sorting....
Get a Random Array Item with JavaScript
9.5.2022
JavaScript Arrays are probably my favorite primitive in JavaScript. You can do all sorts of awesome things with arrays: get unique values, clone them, empty them, etc. What about getting a random value from an array? To get a random item from an array, you can employ Math.random: const arr =...
Array.prototype.at
8.11.2021
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...
Creating Arrays in Hasura
4.1.2021
Hasura is one of my favorite ways to create a managed GraphQL API for my applications. I find it easy and straightforward as well as suitable for a wide range of use cases. However, since working with Hasura, I’ve seen …
The post Creating Arrays in Hasura appeared first on CSS-Tricks.
You...
How to Make localStorage Reactive in Vue
24.6.2020
Reactivity is one of Vue’s greatest features. It is also one of the most mysterious if you don’t know what it’s doing behind the scenes. Like, why does it work with objects and arrays and not with other things, like localStorage?
Let’s answer that that question, and while we’re at it, make...
Level up your .sort game
10.6.2019
Sorting is a super handy JavaScript method that can display the values of an array in a certain order. Whether that’s real estate listings by price, burger joints by distance, or best nearby happy hours by rating, sorting arrays of information is a common need.
If you’re already doing this with...
Using the Grid Shepherd Technique to Order Data with CSS
28.5.2019
Shepherds are good at tending to their sheep, bringing order and structure to their herds. Even if there are hundreds of those wooly animals, a shepherd still herds them back to the farm at the end of the day.
When dealing with data, programmers often don't know if it is correctly filtered...
Type Conversion with JavaScript Arrays
7.5.2019
JavaScript’s loose nature allows developers to employ amazing tricks to do just about anything you’d like. I’ve detailed how you can filter falsy values in arrays using a filter(Boolean) trick, but reader David Hibshman shared another trick for typecasting array values the same...
An Illustrated (and Musical) Guide to Map, Reduce, and Filter Array Methods
26.3.2019
Map, reduce, and filter are three very useful array methods in JavaScript that give developers a ton of power in a short amount of space. Let’s jump right into how you can leverage (and remember how to use!) these super handy methods.
Array.map()
Array.map() updates each individual value in...
The Ultimate Guide to JavaScript Algorithms: Combining Arrays Without Duplicates
19.2.2019
Combining Arrays Without Duplicates
When developing software, we often need to combine data efficiently and without repetition. This often comes up when manipulating listed data with the use Arrays
The Ultimate Guide to JavaScript Algorithms: Finding the Most Recurring Character
23.1.2019
In this challenge, we will be dealing with strings, arrays and objects. We will learn to manipulate these data types using various methods that'd bring us to a working solution in the end.
E
The Ultimate Guide to JavaScript Algorithms: Counting the Vowels in a String of Text
23.1.2019
In this challenge, we will be working with strings and arrays. Strings and arrays are very much alike in that they are both collections of elements usually of the same type.
In order to mani
Does it mutate?
18.1.2019
This little site by Remy Sharp's makes it clear whether or not a JavaScript method changes the original array (aka mutates) or not.
I was actually bitten by this the other day. I needed the last element from an array, so I remembered .pop() and used it.
const arr = ["doe", "ray", "mee"];
const...
Converting Color Spaces in JavaScript
10.1.2019
A challenge I faced in building an image "emojifier" was that I needed to change the color spaces of values obtained using getImageData() from RGB to HSL. I used arrays of emojis arranged by brightness and saturation, and they were HSL-based for the best matches of average pixel colors with...
Understanding the Almighty Reducer
13.6.2018
I was reently mentoring someone who had trouble with the .reduce() method in JavaScript. Namely, how you get from this:
const nums = [1, 2, 3]
let value = 0
for (let i = 0; i < nums.length; i++) {
value += nums[i]
}
...to this:
const nums = [1, 2, 3]
const value = nums.reduce((ac, next)...