Skip to content

Category: JavaScript

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 […]

Timing events in JavaScript

In this article, we will shortly learn about the timing events in JavaScript. Sometimes we may like to execute some part of code certain time later. That’s also called ‘Scheduling […]

String building/concatenation in JavaScript

In this article, we will look some of the commons ways to building / concatenating a String in JavaScript. JavaScript contains a number of features for manipulating strings which are […]

Iterate over Array in JavaScript

In this tutorial we are going to discuss various ways of iterating over an array in JavaScript. This will provide you with a good understanding of exactly how to iterate […]

Validate email address in JavaScript

Find out how to validate an email address in JavaScript. We can use Regular Expression to check if an email address is valid. The regular expression /^([a-zA-Z0-9_.-])+\@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/ check if an […]

Creating a reusable button component in React

Learn how to create a reusable button component in React without having business logic. Reusable components are the React components that can be used multiple times across application code. To […]