Skip to content

Category: JavaScript

Anti-shake throttling in JavaScript

Anti-shake and throttling are both ways to solve performance problems caused by high-frequency trigger events. Anti-shake means that after the event is triggered, wait for a certain period of time […]

Get all dates within range in react js

function (startDate, endDate, addFn, interval) {

 addFn = addFn || Date.prototype.addDays;
 interval = interval || 1;

 var retVal = [];
 var current = new Date(startDate);

 while (current <= endDate) {
  retVal.push(new Date(current));
  current = addFn.call(current, interval);
 }

 return retVal;

}

Get browser name in JavaScript

The userAgent property inside navigator object returns the value of the user-agent header sent by the browser to the server. We can use this property to find out the browser […]

Pad a number with leading zeros in JavaScript

In JavaScript, to pad a number with leading zeros, we can use the padStart() method. The padStart() method pads the current string with another string until the resulting string reaches the given […]

Get all method names of an Object in JavaScript

The Object.getOwnPropertyNames() method returns a string array of all properties implemented directly upon a given object. We can use this method to return all methods in a given object. Syntax Example

Swap two array elements in JavaScript

In this short post, we are going to see about how to swap two array elements in JavaScript. Here, I have listed some methods that I’ve learnt to swap two […]

JavaScript String.prototype.replaceAll

In JavaScript, we can’t replace the all occurance of substring in a string without use of global regex. In our previous post that is Replace all instances of a string […]

Deep Cloning Objects In JavaScript

In this article, we are going to discuss deep cloning objects in JavaScript. In JavaScript, Object play a major role in storing and sharing data. Because objects in JavaScript are […]

JavaScript String method toLowerCase() and toUpperCase()

JavaScript provides two helpful functions for converting text to uppercase and lowercase. String.toLowerCase() converts a string to lowercase String.toUpperCase() converts a string to uppercase. Both methods works in all modern browsers.

Numeric separators in JavaScript

In this post we will learn about the new feature in JavaScript called Numeric Separators which will be introduced in ES2021. Numeric separators enables developers to make their numeric literals […]

Comments in JavaScript

Let’s take a quick look at the JavaScript comments, the following are some of important points about the comments. Comments in JavaScript are used to explain the code and make the program more readable for […]

Split an array into half in JavaScript

Do you want to split an array into half in JavaScript, divide exactly into equal part? You can use the Array.prototype.splice() method When the length of the array is in […]

Breaking the Loop in JavaScript

In this post, we will see how to break out from a loop in JavaScript. When we work with array or an object sometime we need to iterate the each […]

How to find type of variable in JavaScript?

In this tutorial, let’s learn how to identify the type of a variable in JavaScript. In short, the answer in typeof. In JavaScript, the typeof operator returns the data type of its operand in […]

split() String Method in JavaScript

In this short post we will see the use cases of split() method in JavaScript. The split() method separates an original string into an array of sub-strings, based on a separator string that you […]

Array.find Method in JavaScript

In this post let’s take a look at how the Array.find() method works with some easy examples. Array.find() is a JavaScript method that can searches through the array or an […]

Trim String in JavaScript

Today we are going to see how to smash the whitespaces from the String in JavaScript. First let’s see how the whitespaces are created, Space Tab Line terminator character (used […]

String match in JavaScript

Today we are quickly going to look out how the String match() works. This method makes our string contains check easy. Syntax: It allows us to do the creative way […]

Convert an Object to an Array in JavaScript

In this post, we will see how to convert an object to an array in JavaScript. To achieve this we can use below three methods. Object.keys() Object.values() Object.entries() Let’s go […]