Shubham Vora

Shubham Vora

793 Articles Published

Articles by Shubham Vora

Page 7 of 80

How to use map() on an array in reverse order with JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 4K+ Views

The map() method creates a new array by transforming each element. Sometimes you need to process array elements in reverse order. Here are three effective approaches to achieve this. Introduction to map() Method Syntax array.map((element, index, array) => { return element + 20; }) Parameters element – The current array element being processed index – The index of the current element array – The original array being mapped Method 1: Reverse Array Then Map First reverse the array using reverse(), then apply map() to the reversed ...

Read More

How to validate an input is alphanumeric or not using JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 12K+ Views

Validating whether an input contains only alphanumeric characters (letters and numbers, no spaces or special characters) is a common requirement in JavaScript applications. An alphanumeric string contains only numeric digits (0-9) and alphabetical characters (A-Z, a-z). Below are two effective approaches to validate alphanumeric strings in JavaScript. Using the charCodeAt() Method The charCodeAt() method returns the ASCII value of a character. We can iterate through each character and check if its ASCII value falls within the valid ranges: 48-57: Numeric characters (0-9) 65-90: Uppercase letters (A-Z) 97-122: Lowercase letters (a-z) Syntax ...

Read More

How to validate email address using RegExp in JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 15K+ Views

Anyone can make a mistake while entering the email in the input field. So, it's the developer's responsibility to check if users have entered a valid email string. Many libraries are available to validate email addresses, which we can use with various JavaScript frameworks, but not with vanilla JavaScript. However, if we want to use any library, we need to use its CDN. Here, we will use the regular expression to validate the email address in vanilla JavaScript. Basic Email Validation Pattern We have used the below regular expression pattern in our first example to validate the email. ...

Read More

How to zoom in and zoom out images using JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 10K+ Views

The zoom-in and zoom-out functionality is essential for image interaction. By zooming in, users can examine image details closely, while zooming out provides a broader view. This feature is particularly useful for reading small text, viewing detailed graphics, or navigating large images. In this tutorial, we will learn to implement zoom functionality for images using JavaScript by manipulating CSS properties. Using Height and Width Properties The most straightforward approach is to modify the image's height and width properties. By increasing these values, we zoom in; by decreasing them, we zoom out. Syntax // Zoom ...

Read More

How to do case insensitive string comparison of strings in JavaScript

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 2K+ Views

In this tutorial, we will learn how to do a case-insensitive string comparison of strings in JavaScript. Case insensitive comparison means strings should be considered equal regardless of whether they are written in lowercase or uppercase letters. This technique is commonly used in search functionality, where "TutorialsPoint" and "tutorialspoint" should be treated as identical. There are four main methods to perform case-insensitive string comparisons: toUpperCase() toLowerCase() localeCompare() RegExp() Using the toUpperCase() Method The toUpperCase() method converts all alphabetic ...

Read More

How to change string to be displayed as a superscript using JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 3K+ Views

In this tutorial, we will learn how to display strings as superscript using JavaScript and HTML. Superscript text appears raised above the normal text baseline, making it smaller and positioned at half-height. This is commonly used in mathematical formulas like A2, B3, or scientific notations like 105. Superscript is essential for writing mathematical expressions, chemical formulas (like H2O+), and footnote references in web content. Using HTML Tag The simplest way to create superscript text is using the HTML tag. Any text inside this tag will automatically display as superscript. Syntax 102 = ...

Read More

Access an Element in Type Script

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 15K+ Views

In TypeScript, to access HTML elements, we use the Document Object Model (DOM). The DOM defines an HTML and XML programming interface that visualizes a document's structure as a tree of nodes. Each node in the tree represents document elements like paragraphs, buttons, divs, headings, etc. The document object in TypeScript serves as the doorway to the DOM, allowing us to easily access and manipulate HTML elements. There are several ways to access elements: Using the document.getElementById() method Using the document.querySelector() method Using the document.getElementsByClassName() method ...

Read More

Conditional Properties Using React with TypeScript

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 6K+ Views

In React with TypeScript, conditional properties allow you to pass props to components only when certain conditions are met. This technique is essential for creating dynamic, interactive user interfaces that respond to state changes and user interactions. TypeScript enhances this pattern by providing type safety, ensuring that your conditional props are correctly typed and helping catch potential runtime errors during development. Understanding Conditional Properties Conditional properties are props that are only set on a component under specific conditions. In React with TypeScript, you can implement this using: Ternary operator - Returns one value if condition ...

Read More

Duck Typing in TypeScript

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 1K+ Views

Duck typing is a programming concept where an object's type is determined by its behavior (methods and properties) rather than its class inheritance. The name comes from the phrase "If it walks like a duck and quacks like a duck, then it must be a duck." What is Duck Typing? Duck typing focuses on what an object can do rather than what it is. If two objects have the same methods and properties, they can be used interchangeably, regardless of their actual class or type. Duck Typing in TypeScript TypeScript implements duck typing through interfaces. An ...

Read More

Find Hypotenuse of a Number In TypeScript

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 420 Views

The longest side of a right-angled triangle and the side that faces away from the right angle is known as the hypotenuse. The Pythagorean theorem states that the hypotenuse's square equals the sum of the squares of the other two sides. The formula is c² = a² + b², where c is the hypotenuse and a and b are the triangle's two sides. In TypeScript, we can create functions to calculate the hypotenuse using the Pythagorean theorem. The function accepts the lengths of the two shorter sides as parameters and returns the hypotenuse length. This only works for right ...

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