Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Javascript Articles
Page 361 of 534
Replace array value from a specific position in JavaScript
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 MoreHTML5 Input type "number" in Firefox
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 MoreHow to get sequence number in loops with JavaScript?
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 MorePassing mouse clicks through an overlaying HTML element
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 MoreSplit First name and Last name using JavaScript?
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 MoreTranslating HTML5 canvas
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 MoreDetecting HTML click-to-call support in JavaScript
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 MoreHTML 5 Video Buffering a certain portion of a longer video
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 MoreHow to handle mousedown and mouseup with HTML5 Canvas
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 MoreReplace commas with JavaScript Regex?
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