Javascript Object: Find the Key(s) of a given Value
This practical, concise article shows you a couple of different ways to get the key if know its value in a Javascript object. Without any further ado, let’s write some code. Caveat: It is possible that…
Javascript: 2 Ways to Find Min/Max Property of an Object
This short and straight-to-the-point shows you two different ways to get the minimum and maximum properties of a Javascript object (assuming this object has two or more properties with all values being numeric). The Modern Way…
Javascript: 3 Ways to Find Min/Max Number in an Array
This article walks you through a couple of different ways to find the minimum and maximum numbers in a Javascript array. Knowing more than one solution to solve a problem can help you understand Javascript more…
Javascript: How to Reverse an Integer
In Javascript, you can reverse a given integer (e.g. turn 123 to 321, -456 to -654, 1200 to 21) by performing the following steps: Convert the integer to a string Reverse that string Turn the reversed…
3 Ways to Reverse a Given String in Javascript
The three examples below show you three different approaches to reverse a given string in Javascript. Without any further ado, let’s get started. Using Array.reverse() method The code with explanations: Console output: You can shorten the…
Vanilla Javascript: Detect a click outside an HTML element
With Javascript, you can easily detect if the user clicks somewhere outside a given HTML element. For example, the code snippet below shows you how to catch a click outside an element with the id of…
Calculate Variance and Standard Deviation in Javascript
This short article shows you how to calculate the variance and standard deviation of a given array of numbers. You will see the code in vanilla Javascript and TypeScript. Javascript Output: TypeScript If you use TypeScript…
Javascript: Capitalize the First Letter of Each Word (Title Case)
This short article shows you how to capitalize the first letter of each word in a string. hypothetical inputs and expected outputs: we will just capitalize the first letter of a word and keep the rest…
Javascript: Looping through Keys/Values of an Object
The examples below show you how to loop through keys/values of a given object in Javascript. Example 1: Using Object.entries() The entries() method returns an array of a given object. It’s supported in all modern browsers…
Javascript: Set HTML lang attribute programmatically
You can dynamically change the lang attribute of your HTML document just by using pure Javascript like this: For more clarity, take a look at the example below. Example Preview We are going to build a…
Javascript: Display float with 2 decimal places (3 examples)
There are several ways to format a float with 2 (or any number you want) decimal places in Javascript. Example 1: Using toFixed() The code: Output: Example 2: Using toLocaleString() The code: Output: Example 3: Using…
Javascript: Merging multiple arrays with spread syntax
In order to merge (or concatenate) two, three, or more arrays in ES6, we can use the spread syntax. Example: Output: Note: Using the spread syntax does not change the existing arrays. It always returns a…
« Previous 1 2 3 Next »