Javascript Object: Find the Key(s) of a given Value

June 23, 2022 A Goodman

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

June 23, 2022 A Goodman

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

June 23, 2022 A Goodman

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

June 23, 2022 Napoleon

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

June 22, 2022 Napoleon

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

June 13, 2022 Pennywise

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

November 15, 2021 Napoleon

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)

November 9, 2021 A Goodman

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

September 6, 2021 A Goodman

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

July 21, 2021 A Goodman

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)

July 16, 2021 A Goodman

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

February 13, 2022 A Goodman

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…