Pretty-print a JSON object with JavaScript
Pretty-printing JSON objects in pretty easy and customizable in JavaScript. Here's the gist of it.
Finding ways to improve and optimize your code takes a lot of time, research and energy. Level up your coding skills one step at a time with this collection of quick tips and tricks.
Pretty-printing JSON objects in pretty easy and customizable in JavaScript. Here's the gist of it.
Learn how to capitalize the first letter of a string in JavaScript using array destructuring and String.prototype.toUpperCase()
.
Learn how to replicate the behavior of Array.prototype.map()
for strings.
Generate the powerset of a given array of numbers or other primitive values.
Learn how to remove accents from a string in JavaScript, quickly and efficiently.
Circular JSON objects can't be serialized using JSON.stringify()
, but you can use this trick to handle them.
Create a new array out of the two supplied by creating each possible pair from the arrays.
Array destructuring can be leveraged in many different ways. Here's one of them.
Quickly find the minimum or maximum date in an array of dates.
Quickly and easily check if a string is a yes/no answer to a boolean question in your CLI programs.
Injecting CSS into a page via JavaScript is pretty easy, if you know how to leverage the DOM.
Learn how to filter branches based on whether they contain a specific commit or not.
Avoid the naive approach and use a more robust method to edit URL parameters in JavaScript.
Using Document.elementFromPoint()
to easily get the element at a specific point on the page.
Learn how to execute a function for each element of an array, starting from the last one.
Use JavaScript to generate a random alphanumeric string of a specified length.
In React components, you might need to conditionally apply a className
. Learn how to handle empty values correctly using this handy tip.
Learn how to quickly write code to sort JavaScript arrays with this handy one-liner.
Turns out the Proxy object is not extensible, but there's a way around its limitations.
Here's a quick tip on how to compare and sort arrays of strings, ignoring case and accents.
Dynamically adding object properties can be pretty slow in some cases. Here's how to optimize it.
There are many ways to create empty links, some more appropriate than others. Learn how to best handle empty links with this quick tip.
The currentColor
CSS keyword is a nifty alternative to custom properties for simple use cases.
Create a debounced function that waits a certain amount of time before invoking the provided function again.