Javascript Articles

Page 361 of 534

Replace array value from a specific position in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 584 Views

To replace a value at a specific position in a JavaScript array, you can use the splice() method or direct index assignment. Both approaches modify the original array. Using splice() Method The splice() method removes elements and optionally adds new ones at a specified position. Syntax array.splice(index, deleteCount, newElement) Example var changePosition = 2; var listOfNames = ['John', 'David', 'Mike', 'Sam', 'Carol']; console.log("Before replacing:"); console.log(listOfNames); var name = 'Adam'; var result = listOfNames.splice(changePosition, 1, name); console.log("After replacing:"); console.log(listOfNames); console.log("Removed element:", result); Before replacing: [ 'John', ...

Read More

HTML5 Input type "number" in Firefox

karthikeya Boyini
karthikeya Boyini
Updated on 15-Mar-2026 980 Views

The HTML5 input type "number" provides built-in validation and spinner controls for numeric input. However, browser support for certain attributes like min and max has varied across different versions of Firefox. Browser Support Overview Modern Firefox versions (52+) fully support the min and max attributes for number inputs. Earlier Firefox versions had limited support, but this is no longer an issue for current web development. Example Here's a complete example demonstrating the number input with validation attributes: HTML5 Number Input ...

Read More

How to get sequence number in loops with JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 1K+ Views

To get sequence numbers in loops with JavaScript, you can use various approaches. The most common method is maintaining a counter variable that increments with each iteration. Using forEach() with External Counter The forEach() method provides an elegant way to iterate through arrays while maintaining sequence numbers using an external counter: let studentDetails = [ { id: 101, details: [{name: 'John'}, {name: 'David'}, {name: 'Bob'}] }, { ...

Read More

Passing mouse clicks through an overlaying HTML element

Ankith Reddy
Ankith Reddy
Updated on 15-Mar-2026 1K+ Views

When you have an overlaying HTML element that blocks mouse clicks to elements beneath it, you can pass clicks through using CSS or JavaScript techniques. Method 1: Using CSS pointer-events The simplest approach is to use the CSS pointer-events property to make the overlay non-interactive: .overlay { pointer-events: none; } Example: CSS pointer-events .overlay { position: absolute; ...

Read More

Split First name and Last name using JavaScript?

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

In JavaScript, you can split a full name into first and last name using the split() method. This method divides a string based on a specified separator and returns an array of substrings. Syntax string.split(separator) Basic Example var studentFullName = "John Smith"; var details = studentFullName.split(' '); console.log("Student First Name = " + details[0]); console.log("Student Last Name = " + details[1]); Student First Name = John Student Last Name = Smith Handling Multiple Names For names with more than two parts, you can extract the first ...

Read More

Translating HTML5 canvas

Nishtha Thakur
Nishtha Thakur
Updated on 15-Mar-2026 471 Views

Use the translate() method to move the HTML5 canvas coordinate system. The translate(x, y) method shifts the canvas origin to a different point in the grid. The x parameter moves the canvas left (negative) or right (positive), and y moves it up (negative) or down (positive). Syntax context.translate(x, y); Parameters Parameter Description x Horizontal distance to ...

Read More

Detecting HTML click-to-call support in JavaScript

Ankith Reddy
Ankith Reddy
Updated on 15-Mar-2026 296 Views

The tel: protocol enables click-to-call functionality on mobile devices. Most modern browsers support it, but older devices may require different protocols or detection methods. Basic tel: Protocol Support Modern mobile browsers support the tel: protocol natively: Click to Call Example Call +1 (234) 567-890 // Check if tel: links are supported function isTelSupported() { ...

Read More

HTML 5 Video Buffering a certain portion of a longer video

Krantik Chavan
Krantik Chavan
Updated on 15-Mar-2026 783 Views

The TimeRanges object in HTML5 allows you to work with buffered portions of video and audio elements. It represents a series of non-overlapping time ranges that have been buffered by the browser. TimeRanges Properties The TimeRanges object provides the following properties: length − Number of buffered time ranges start(index) − Start time of a specific range, in seconds end(index) − End time of a specific range, in seconds Accessing Buffered Ranges You can access buffered ranges using the buffered property of video or audio ...

Read More

How to handle mousedown and mouseup with HTML5 Canvas

Daniol Thomas
Daniol Thomas
Updated on 15-Mar-2026 909 Views

To handle the mousedown and mouseup events with HTML5 Canvas, you can attach event listeners directly to the canvas element. These events are useful for creating interactive graphics, drag-and-drop functionality, or drawing applications. Basic Syntax canvas.addEventListener('mousedown', function(event) { // Handle mouse press }); canvas.addEventListener('mouseup', function(event) { // Handle mouse release }); Example: Simple Click Detection const canvas = document.getElementById('myCanvas'); const ctx = canvas.getContext('2d'); let mouseDown = false; // Draw initial state ctx.fillStyle = '#f0f0f0'; ctx.fillRect(0, 0, 400, 300); ctx.fillStyle = ...

Read More

Replace commas with JavaScript Regex?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 756 Views

In JavaScript, you can replace commas in strings using the replace() method combined with regular expressions. This is particularly useful when you need to replace specific comma patterns, such as the last comma in a string. Problem Statement Consider these example strings with commas: "My Favorite subject is, " "My Favorite subject is, and teacher name is Adam Smith" "My Favorite subject is, and got the marks 89" We want to replace the last comma in each string with " JavaScript". Using Regular Expression to Replace Last Comma The regular expression /, ...

Read More
Showing 3601–3610 of 5,340 articles
« Prev 1 359 360 361 362 363 534 Next »
Advertisements