Make numbers in array relative to 0 – 100 in JavaScript

AmitDiwan
Updated on 15-Mar-2026 23:18:59

310 Views

Let's say, we have an array that contains some numbers, our job is to write a function that takes in the array and maps all the values relative to 0 to 100. This means that the greatest number should get replaced by 100, the smallest by 0, and all others should get converted to specific numbers between 0 and 100 according to the ratio. Understanding the Formula To normalize values to a 0-100 scale, we use the formula: normalizedValue = ((value - min) / (max - min)) * 100 This formula ensures the smallest ... Read More

How do I display only the visible text with jQuery?

AmitDiwan
Updated on 15-Mar-2026 23:18:59

598 Views

To display only the visible text in jQuery, use the :visible selector. This selector targets elements that are currently visible on the page (not hidden with display:none, visibility:hidden, or other hiding methods). Syntax $(selector).filter(':visible') $(selector + ':visible') $(':visible') Example Visible Text with jQuery Hidden Text Visible Text ... Read More

Fetch values by ignoring a specific one in JavaScript?

AmitDiwan
Updated on 15-Mar-2026 23:18:59

439 Views

To ignore a specific value when fetching data from an array or object, use the logical NOT (!) operator in conditional statements to exclude unwanted values and retrieve only the ones you need. Using NOT Operator with Array of Objects The most common approach is to loop through your data and use the inequality operator (!=) to skip specific values: var customerDetails = [ { customerName: "John", customerAge: 28, customerCountryName: "US" }, ... Read More

Digit distance of two numbers - JavaScript

AmitDiwan
Updated on 15-Mar-2026 23:18:59

423 Views

We are required to write a JavaScript function that takes in two numbers and returns their digit distance. What is Digit Distance? The digit distance of two numbers is the absolute sum of the difference between their corresponding digits from left to right. For example, if the numbers are: 345 678 Then the digit distance calculation will be: |3-6| + |4-7| + |5-8| = 3 + 3 + 3 = 9 Implementation Here's how to calculate digit distance in JavaScript: const num1 = 345; const num2 ... Read More

What is the difference between JavaScript undefined and void(0)?

Alshifa Hasnain
Updated on 15-Mar-2026 23:18:59

928 Views

In this article, we will learn the difference between JavaScript undefined and void(0). Though they may appear similar, they serve distinct purposes and can be used in different scenarios. What is JavaScript undefined? undefined means a variable declared, but no value has been assigned. It is a primitive value automatically assigned to variables that have been declared but not initialized. For Example − var demo; console.log(demo); // shows undefined console.log(typeof demo); // shows undefined undefined undefined It is a global property that represents a variable ... Read More

How to remove options from a dropdown list with JavaScript?

Prabhdeep Singh
Updated on 15-Mar-2026 23:18:59

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 set the gap between the columns with JavaScript?

Shubham Vora
Updated on 15-Mar-2026 23:18:59

2K+ Views

In this tutorial, we will learn how to set the gap between the columns with JavaScript. The readability of lengthy paragraphs or articles is improved by dividing them into multiple columns. The text is divided into multiple columns using the 'column-count' CSS property. There needs to be a space or gap between the columns to make each column separate from the other. To set the gap between the columns with JavaScript, we have multiple ways, and in this tutorial, we will discuss two of them − Using the style.columnGap property ... Read More

Set border width with CSS

Lakshmi Srinivas
Updated on 15-Mar-2026 23:18:59

445 Views

The border-width property allows you to set the width of element borders. The value of this property could be either a length in px, pt or cm or it should be set to thin, medium or thick. Syntax border-width: value; /* Individual sides */ border-top-width: value; border-right-width: value; border-bottom-width: value; border-left-width: value; /* Shorthand for all sides */ border-width: top right bottom left; Values The border-width property accepts the following values: Length units: px, pt, em, rem, cm, mm Keywords: thin, medium, thick Global values: initial, inherit, unset ... Read More

Explain JavaScript Regular Expression modifiers with examples

AmitDiwan
Updated on 15-Mar-2026 23:18:59

732 Views

JavaScript regular expression modifiers are optional flags that modify how the pattern matching behaves. These modifiers enable features like case-insensitive matching, global searching, and multiline matching. Available Modifiers Modifier Name Description ... Read More

How to combine 2 arrays into 1 object in JavaScript

AmitDiwan
Updated on 15-Mar-2026 23:18:59

827 Views

Let's say, we have two arrays of equal lengths and are required to write a function that maps the two arrays into an object. The corresponding elements of the first array becomes the corresponding keys of the object and the elements of the second array become the value. We will reduce the first array, at the same time accessing elements of the second array by index. This is a common pattern for creating objects from parallel arrays. Using Array.reduce() Method const keys = [ 'firstName', 'lastName', 'isEmployed', ... Read More

Advertisements