Mask a JavaScript value
Replace all characters in a string, except for the ending characters, with a mask character.
30 seconds of code contains a curated collection of code articles covering a wide range of development needs. The collection spans many topics, ranging from simple coding problems to theoretical concepts and development techniques.
Replace all characters in a string, except for the ending characters, with a mask character.
Learn how to work with arrays of numbers in JavaScript, performing common math operations such as sum, average, product and more.
Learn how to convert between Maps and objects in JavaScript.
Learn how to check if an element is visible in the browser's viewport, using this simple technique.
Learn how to create a string with uppercase characters converted to lowercase and vice versa.
When working with objects, you'll often need to check if a value or key exists, and these snippets will show you how to do just that.
Generate all permutations of an array's elements or a string's characters using recursion.
Injecting CSS into a page via JavaScript is pretty easy, if you know how to leverage the DOM.
Learn how to use regular expressions to replace the last occurrence of a pattern in a JavaScript string.
Learn how to remove accents from a string in JavaScript, quickly and efficiently.
Learn how to create a generator function that repeats a given value or an array of values indefinitely.
Learn how to easily convert any string to a SEO-friendly slug, using regular expressions.
Learn how to change the lightness component of an hsl() color string using JavaScript.
Learn how to check if two numbers are approximately equal to each other in JavaScript.
Learn how to convert a 3-digit RGB notated hexadecimal color-code to the 6-digit form.
Learn how to generate a random hexadecimal color code with a few lines of JavaScript.
Learn how to write a JSON object to a file, both using Node.js and in the browser.
When formatting decimal values in JavaScript, trailing zeros can be undesired. Here's how to deal with them.
Learn how to leverage partial application to improve the reusability of your JavaScript functions.
Learn how to check if an array has one or more values matching the given function, and how to find the matching elements.
Learn how to insert an HTML string before or after the start of a specified element using JavaScript.
Learn how to work with whitespaces in JavaScript strings, using these simple yet powerful regular expression techniques.
Learn different ways to memoize function calls in JavaScript as well as when to use memoization to get the best performance results.
Learn how to check if a number is prime and how to generate prime numbers up to a given number in JavaScript.