Posts by Devsheet

Read all articles posted by Devsheet programmers and content writers.

How to make HTTP requests using Javascript Only

In JavaScript, you can make an HTTP request using the built-in XMLHttpRequest object or the new fetch() function. We will explain all methods in this post.

Add a month to Date in Javascript

Adding a month to a date in JavaScript is a common task that is often used in scheduling, calendar, or date-related applications. In JavaScript, the Date object provides several methods that can be used to manipulate dates, such as setMonth, setDate, and getMonth. By using these methods, it's possible to add a specified number of months to a date and obtain the resulting date.

Javascript to find which DOM element has the focus

In JavaScript, you can use the document.activeElement property to determine which DOM element currently has the focus. This property returns the element that currently has focus, or null if no element has focus.

Efficiently Remove the Last Element from an Array in JavaScript [6 Methods Explained]

Welcome to our guide on how to efficiently remove the last element from an array in JavaScript. In this tutorial, we will be discussing six different methods that can be used to accomplish this task.

Get Tag Name of an Element using Javascript

In JavaScript, the tag name of an HTML element can be retrieved using the .tagName property. The .tagName property returns a string representing the tag name of the provided element.

Get the largest value from an array using javascript

In this post, we will learn different methods and functions to get the largest value from an array. We will use Math.max() function in order to do that along with other methods with explanation.

While loop in Javascript with examples

In JavaScript, a while loop is a control flow statement that allows you to execute a block of code repeatedly as long as a certain condition is true. In this post we will explain the while and do-while loop of Javascript with examples.

How to iterate over an object in Javascript

Iterating over an object in Javascript can be a great way to access data stored within the object. By looping over an object, you can get the specific values of the object keys, which can be a helpful tool when trying to access and manipulate data. In this article, you'll learn how to iterate over an object in Javascript and use it to access the data stored within.

Remove an object from array by value in Javascript

There are multiple ways that can be used to remove an object based on the value in Javascript. We will explain them one by one in this post.

Check if string includes a substring Javascript (Multiple Methods)

If you're working with strings in JavaScript, it's often useful to know whether or not a string includes a particular substring. For example, you might want to check if a string contains a URL or a specific word. In this article, we will show you different methods to check that.

Filter an Array using object key value in Javascript

If you have an array of objects and you want to filter the array by a key value, you can use the filter() method in JavaScript. The filter() method creates a new array with all the elements that pass the test implemented by the callback() function.

Using regex to validate a phone number in Javascript

Validating phone numbers is an important part of any web form. There are many ways to do this, but one of the most effective is to use a regular expression, or "regex." Regex can be used to validate a wide variety of data, including phone numbers. Here, we'll show you how to use regex to validate a phone number in Javascript. We'll also provide a few tips on how to make sure your phone number regex is as effective as possible.

Javascript examples to remove url from a string

If you're looking for a way to remove the url from a string using Javascript, you've come to the right place. In this article, we'll show you a few different examples of how to do this.

Find the Third Smallest Number in an Array using Javascript

If you're looking for a quick and easy way to find the third smallest number in an array using Javascript, you've come to the right place. In this article, we'll show you how to do just that with a few simple lines of code.

Send Form Data in axios POST request

When using axios, a Javascript library for making HTTP requests, to make a POST request, you need to set the data that you want to send as the body of the request. To do this, you can use the axios.post() method, which takes two arguments: the URL of the server you want to send the request to, and the data you want to send. In this article, we will look at how to use axios to make a POST request, and how to set the body of the request.

Sort array of objects by key value in Javascript

If you have an array of objects and you want to sort them by a key value, you can use the sort() method. The sort() method takes a callback function as an argument. The callback function takes two arguments, a and b. The sort() method will compare the a and b arguments and return a negative number if a is less than b, a positive number if a is greater than b, or 0 if a is equal to b.

Simplest Way to Find the Smallest Number in an Array using JavaScript

If you're looking for the simplest way to find the smallest number in an array using JavaScript, you've come to the right place. In this article, we'll show you how to do it with just a few lines of code.

Check if array contains duplicate values in Javascript

In Javascript, there are many ways to check if an array contains duplicate values. One way is to use the Set data structure, which can only contain unique values. Another way is to use a for loop to iterate through the array and keep track of values that have been seen before in a separate data structure. If a value is seen more than once, then the array contains duplicates.

Find the index of Max value in an array using Javascript

We will be discussing how to find the index of the maximum value in an array using Javascript. This is a simple task that can be accomplished by using the built-in Math.max() function. However, this function only returns the maximum value, not the index. To get the index, we will use Array.indexOf() function.

Access object properties using with() function in Javascript(ES6)

ES6 provides a new way to access object properties using the with() function. This is a more convenient way to access object properties, especially when working with large objects.

Javascript to split string into array of characters

If you're working with JavaScript, you may occasionally need to take a string and split it into an array of individual characters. While this might seem like a simple task, there are actually a few different ways to accomplish this. In this article, we'll take a look at a few different ways to split a string into an array of characters.

Run a Javascript file in Terminal window

In order to run a Javascript file in a Terminal window, the file must first be saved with a ".js" extension. Then, the file can be run using the command "node filename.js".

Get text before @ in an email using Javascript

Before we get into how to get the text before the @ in an email using Javascript, it's important to understand what an email address is. An email address is made up of two parts: the username and the domain. The username is the part of the email address that comes before the @ symbol, and the domain is the part that comes after. So, how can we get the text before the @ in an email using Javascript? The answer is quite simple. We can use the indexOf() method to find the position of the @ symbol in the email address, and then use the substring() method to get the text before it.

Javascript function to get cookie value by name

A function to get cookie value by name would be extremely useful for web developers who want to create dynamic web pages. By being able to access the value of a cookie, developers can store user preferences or track user behavior.

Remove all cookies from the current website using Javascript

Cookies are small pieces of data that are stored on a user's computer when they visit a website. Cookies can be used to store information about a user's preferences or to track a user's activity on a website.

Show confirmation alert before submitting a form in Javascript

In this post, we will learn how to show a confirmation alert before submitting a form in Javascript. This is a great way to avoid accidental submissions and preserve data integrity.

Get number of keys in an object Javascript

In this article, we are going to explain the code examples that can be used to get the number of keys from an object using Javascript.

Remember previously entered data in an input field using local storage in Javascript

If you are using input fields in your application and want the input to remember the previously entered data by the user then you can use Javascript local storage. We are explaining it in this post with working code examples and a demo.

Create dummy APIs using json-server node module

The node package json-server can be used to create dummy REST APIs within no time. You can install the json-server module on your local system and use those apis for testing and development purpose.

Check if Array includes String(Case Insensitive) Javascript

There are multiple methods that can be used to check whether a string exists inside an array as an item or not. But if you want to check the string ignoring if it is lowercase or uppercase then you can use the code examples explained in this post.

Join two arrays and remove duplicate elements using Javascript

In this post, you will learn to merge two arrays and remove duplicate values from them after merging. We will explain different methods in Javascript to do this task.

Check if a number is odd or even using Javascript

There are multiple ways in Javascript to check if a given value is even or odd. We will be explaining the methods one by one in this post.

Pass a function as parameter of another function in Javascript

In javascript, if you have a function that executes a block of code and you want to pass this function as a parameter of another function. You can use the code examples explained here.

Remove all whitespaces from a string using javascript

If you have a String that contains multiple whitespaces in it and want to remove all the whitespace from that string then you can use the code examples used in this post. We will be removing them using regex and without using regex.

Remove a key or property from Object in Javascript

To remove a property or key-value pair from an object using Javascript, you can use the delete keyword. You will need to pass the key name that you want to delete.

Validate a url using regex in Javascript

If you want to check if a URL string is valid or not, you can use regular expressions in Javascript. You can test any string against that regex and it will return true if the URL is valid.

Add months to a date in Javascript

If you are using Date in Javascript and want to add months to the date then you can use the Javascript code examples explained in this post.

Add a CSS class to element if dark mode is enabled using Javascript

In this post, we are adding a class to an HTML element if the user has set dark mode on the system. We are using Javascript code for that.

Check if dark mode is enabled using Javascript

In this post, we can learn how to check if dark mode is enabled on the system or not using javascript code.

Methods to shuffle an array using javascript

In this post, we are going to explain different methods that can be used to shuffle an array in javascript. We will be randomizing the array and putting the array elements in different orders each time the function is executed.

Loading more...
Search all posts...