Abhishek

Abhishek

68 Articles Published

Articles by Abhishek

Page 2 of 7

How to solve the issue that arise while using performance.now() method in JavaScript?

Abhishek
Abhishek
Updated on 15-Mar-2026 289 Views

The performance.now() method measures code execution time in milliseconds, but it has limitations when comparing algorithm efficiency. This article explores common issues and better alternatives for performance analysis. What is performance.now()? The performance.now() method returns a high-resolution timestamp representing the elapsed time since the page loaded. It's more precise than Date.now() for measuring performance. Syntax var startTime = performance.now(); // Your code here var endTime = performance.now(); var executionTime = endTime - startTime; Common Issues with performance.now() While useful for basic timing, performance.now() has several limitations: Small execution times: For ...

Read More

How to sort a map in JavaScript?

Abhishek
Abhishek
Updated on 15-Mar-2026 2K+ Views

In JavaScript, Map is a data structure that stores values as key-value pairs. Maps preserve insertion order, but you can sort them by converting to an array, sorting, and creating a new Map. Syntax To sort a Map in JavaScript, use this approach: var sortedMap = new Map([...originalMap].sort(compareFunction)); Where compareFunction defines the sorting criteria for the key-value pairs. Sorting by Keys (Ascending) Here's how to sort a Map by keys in ascending order: Sorting Map by Keys (Ascending) ...

Read More

How to change the ID of the element using JavaScript?

Abhishek
Abhishek
Updated on 15-Mar-2026 5K+ Views

Generally, the ID given to any element in an HTML document is unique and can be assigned to an element only once. However, it is possible to change that ID later using JavaScript while following the same rule of uniqueness for the new ID. In this article, we will learn how to change the ID of an element using JavaScript. JavaScript provides the id property to get the ID of any element as well as to change or add a new ID to any HTML element in the document. Syntax The following syntax shows how to use ...

Read More

How to change the shape of a textarea using JavaScript?

Abhishek
Abhishek
Updated on 15-Mar-2026 482 Views

A textarea is an HTML element that provides a multi-line text input field with dynamic width and height. By default, textareas appear as rectangular boxes, but you can change their shape using JavaScript to modify CSS properties. In this article, we'll explore different methods to transform textarea shapes using JavaScript, including creating parallelograms and ellipses through CSS property manipulation. Using transform Property for Parallelogram Shape The transform property with skew() function can transform a rectangular textarea into a parallelogram by skewing it along the X or Y axis. Syntax element.style.transform = "skew(angle)"; ...

Read More

How to change the src attribute of an img element in JavaScript / jQuery?

Abhishek
Abhishek
Updated on 15-Mar-2026 16K+ Views

There are different methods to change the path of an image given to the src attribute of an img element in HTML document using JavaScript and jQuery. Method of changing the src attribute of an img element using JavaScript: Use the src property in JavaScript. Methods of changing the src attribute of an img element using jQuery: Using attr() method Using prop() method Let us discuss each of the above listed methods of changing the src of an img element one by one in ...

Read More

How to change the text and image by just clicking a button in JavaScript?

Abhishek
Abhishek
Updated on 15-Mar-2026 22K+ Views

In JavaScript, you can dynamically change text content and images by using the onclick event with button elements. This allows for interactive web pages where content updates in response to user actions. Let us explore how to change text and images individually using JavaScript with practical examples. Changing Text of an Element JavaScript provides two main properties for modifying element text content: innerText − Changes or retrieves the plain text content of an element, ignoring HTML tags. innerHTML − Changes or retrieves the HTML content of an element, including any HTML tags within it. ...

Read More

How to change the text of a label using JavaScript?

Abhishek
Abhishek
Updated on 15-Mar-2026 6K+ Views

The HTML tag improves web accessibility by providing clickable text descriptions for form elements. In JavaScript, you can dynamically change label text using two properties: innerHTML and innerText. Using the innerHTML Property The innerHTML property allows you to set both text and HTML markup. It's useful when you need to include formatting like bold, italics, or other HTML elements. Syntax selectedElement.innerHTML = "new text with HTML tags"; Example Change Label Text with innerHTML Original label text ...

Read More

How to Change the Time Interval of setinterval() Method at RunTime using JavaScript ?

Abhishek
Abhishek
Updated on 15-Mar-2026 3K+ Views

The setInterval() method is used to call a particular block of code repeatedly after a specific time interval. It accepts two parameters: the function to execute and the time interval in milliseconds. Sometimes you need to change this interval dynamically during runtime for irregular or variable timing patterns. JavaScript provides two main approaches to change the time interval of setInterval() at runtime: Using the clearInterval() method Using the setTimeout() method Let us understand both approaches with practical examples. Using the clearInterval() Method The clearInterval() method stops a ...

Read More

How to change the value of a global variable inside of a function using JavaScript?

Abhishek
Abhishek
Updated on 15-Mar-2026 4K+ Views

In JavaScript, variables can be declared with either global or local scope. Understanding how to modify global variables from within functions is essential for managing application state. Global Variables are declared outside any function and can be accessed from anywhere in the code. Local Variables are declared inside functions and are only accessible within that specific function scope. There are two main approaches to change global variable values inside functions: Direct assignment Using window object with bracket notation Method 1: Direct Assignment The most straightforward way is to directly assign a new value ...

Read More

How to find the largest number contained in a JavaScript array?

Abhishek
Abhishek
Updated on 15-Mar-2026 12K+ Views

In this tutorial, we will learn about the different methods to find the largest number contained inside a JavaScript array. An array is a collection of different values, and we need efficient ways to identify the maximum value. There are three main approaches to find the largest number in a JavaScript array: Traversing the Whole Array Using the reduce() Method Using the Math.max() and apply() methods Using Array Traversal (For Loop) This is the most straightforward approach where we iterate through each element and compare it with the current largest value. Algorithm Steps ...

Read More
Showing 11–20 of 68 articles
« Prev 1 2 3 4 5 7 Next »
Advertisements