Prabhdeep Singh

Prabhdeep Singh

161 Articles Published

Articles by Prabhdeep Singh

Page 7 of 17

How to remove leading zeros from a number in JavaScript?

Prabhdeep Singh
Prabhdeep Singh
Updated on 15-Mar-2026 21K+ Views

In this tutorial, we will explore how we can remove leading zeroes from any number in JavaScript. JavaScript removes leading zeroes from an integer variable automatically, but this is not the case when we consider strings in JavaScript. It is possible that a string in JavaScript which represents a numerical value may contain leading zeroes. These leading zeroes may cause problems when we try to perform any operation on the numerical value the string represents. This is why we will explore the ways by which we can remove the leading zeroes from a number, expressed as a string in ...

Read More

How to select multiple options in a dropdown list with JavaScript?

Prabhdeep Singh
Prabhdeep Singh
Updated on 15-Mar-2026 11K+ Views

In JavaScript, you can enable multiple selection in a dropdown list by setting the multiple property to true. This allows users to select multiple options by holding Ctrl (Windows) or Cmd (Mac) while clicking. Syntax function enableMultipleSelection() { document.getElementById("selectId").multiple = true; } How It Works The multiple property controls whether a select element allows multiple selections. When set to true, users can select multiple options using keyboard modifiers: Ctrl + Click (Windows/Linux) to select multiple individual options Cmd + Click (Mac) to select multiple individual options Shift + Click ...

Read More

How to remove options from a dropdown list with JavaScript?

Prabhdeep Singh
Prabhdeep Singh
Updated on 15-Mar-2026 14K+ Views

This tutorial teaches us how to remove options from a dropdown list using JavaScript. Usually, this is not frequent that users get the option to remove any option from the dropdown list but this is possible if the option is provided by the programmer. If the programmer wants to provide the option to remove the dropdown then in JavaScript it is possible with the help of the remove() method. Using the DOM user can select the option to remove and by providing a function it could be passed to the remove method which will remove it. Let's look into ...

Read More

How to return the protocol (http or https) of the web page with JavaScript?

Prabhdeep Singh
Prabhdeep Singh
Updated on 15-Mar-2026 1K+ Views

In this tutorial, we will look at how to find which protocol is being used by a web page. A web page mostly uses http or https protocol. A protocol is a type of standard which is used to specify how the data is transferred or transmitted between different sets of computers. HTTP − HTTP is a protocol for retrieving resources such as HTML pages. It is one of the most essential and the backbone for all types of data exchange that happens over the internet. HTTP is a client-server protocol which means that all the requests are done ...

Read More

How to replace string using JavaScript RegExp?

Prabhdeep Singh
Prabhdeep Singh
Updated on 15-Mar-2026 3K+ Views

In this tutorial, we will explore how to replace a particular substring in a string using regular expressions in JavaScript. Sometimes we may want to replace a recurring substring in a string with something else. In such cases, regular expressions can be beneficial. Regular expressions are basically a pattern of characters that can be used to search different occurrences of that pattern in a string. Regular expressions make it possible to search for a particular pattern in a stream of characters and replace it easily. For example, consider the regular expression /ab*c/ which denotes that we are looking for ...

Read More

How to return a number of bits used to display one color on a window screen in JavaScript?

Prabhdeep Singh
Prabhdeep Singh
Updated on 15-Mar-2026 301 Views

In this tutorial, we will explore how we can find out the number of bits that are used to display a single color on the screen of our device using JavaScript. JavaScript has many inbuilt functions that allow us to get information about the various properties of the display screen. We'll be using one such function to accomplish the task mentioned above. As discussed in the previous section, we want to find out the exact number of bits that are used to display a particular color on the user's display screen by using JavaScript. Before we can access the ...

Read More

How to remove two parts of a string with JavaScript?

Prabhdeep Singh
Prabhdeep Singh
Updated on 15-Mar-2026 3K+ Views

This tutorial teaches us how to remove the text part between two parts of a string with JavaScript. We are given two ends that can be a string or a character and we need to remove the string lying in between them. We will use regular expressions with JavaScript's replace() method to accomplish this task. Syntax Here's the basic syntax for removing part of a string between two characters or sub-strings: var str = "your string here"; var final_str = str.replace(/(first_part).*?(second_part)/, '$1$2'); In the above syntax: first_part - The starting delimiter (string ...

Read More

How to serialize a JavaScript array?

Prabhdeep Singh
Prabhdeep Singh
Updated on 15-Mar-2026 3K+ Views

In JavaScript, serializing an array means converting it into a string format that can be stored, transmitted, or reconstructed later. While jQuery's serializeArray() method is useful for form data, JavaScript provides native methods for general array serialization. What is Array Serialization? Array serialization converts a JavaScript array into a string representation. The most common approach uses JSON.stringify() to convert arrays into JSON strings, which can be easily transmitted to servers or stored in local storage. Using JSON.stringify() (Recommended) The JSON.stringify() method is the standard way to serialize JavaScript arrays: // Simple array serialization let ...

Read More

How to return the position of the element relative to floating objects in JavaScript?

Prabhdeep Singh
Prabhdeep Singh
Updated on 15-Mar-2026 555 Views

This tutorial teaches us how to return the position of the element relative to floating objects in JavaScript. To set the relative position or to get or return the relative position we are going to use the 'clear' property of JavaScript which is defined under the style property of an object. The CSS clear property controls how an element behaves next to floating elements. It can have values like 'left', 'right', 'both', or 'none'. When an element has the clear property set, it will move down to avoid overlapping with floated elements on the specified side. Syntax ...

Read More

How to reset or clear a form using JavaScript?

Prabhdeep Singh
Prabhdeep Singh
Updated on 15-Mar-2026 45K+ Views

This tutorial teaches us how to reset or clear a form using JavaScript. This option is very helpful for users when they have filled the wrong data and want to clear everything at once. The reset() method provides an efficient way to restore all form fields to their initial values. The reset() method is a built-in JavaScript function that clears all input fields in a form and restores them to their default values. Syntax document.getElementById("formId").reset(); // or document.forms["formName"].reset(); The getElementById() method retrieves the form element by its ID, and then reset() clears all form ...

Read More
Showing 61–70 of 161 articles
« Prev 1 5 6 7 8 9 17 Next »
Advertisements