Sometimes, we may need to round off time or duration, on quarterly basis. The below table explains it better: Actual timeQuarterly rounded00:1200:1501:0701:0002:2502:3000:5201:0000:0400:00 To round the time or duration quarterly, you…
Format a number to 2 decimal places without rounding off | JavaScript | Example
Here you'll learn how you can format a number to 2 decimal places without rounding it off. By default, the toFixed() method would round off the number to the specified…
Format a number to 2 decimal places in JavaScript | Example
In JavaScript, you can use the toFixed() method to specify the number of digits you want after the decimal place. So, you can simply pass in 2 to toFixed() lead…
Add zero padding to numbers in JavaScript | Example
Sometimes you'd want to fill in digits with zeroes instead of nothing when showing time or something similar. For instance, you'd probably want to show 12:05 instead of 12:5 for…
Convert string to number in JavaScript | 5 ways | Example
Earlier we've seen 6 ways to convert a number to a string in JavaScript. Now, let's have a look at how you can convert a string to a number in…
Convert number to string in JavaScript | 6 ways | Example
JavaScript is a dynamic and flexible, non strongly-typed language. While it opens a few doors for erroneous coding patterns, it also comes with several advantages. One of those is the…
Replace a word/substring in a string in JavaScript | Example
You can replace any word or characters you want in JavaScript using the replace() method. One of the powerful features of the replace method is that not only can it…
Insert an array of objects at Nth place in an array in JavaScript | Example
In this tutorial I'm going to show you how you can insert a list of items at a particular index (and the following indices) in another array. If you want…
Insert an object at Nth position in an array of objects in JavaScript | Example
We can easily insert an object at a particular, known position in an array of objects. We can do so by first breaking the array into segments and then merging…