Javascript Articles

Page 359 of 534

How to split string when the value changes in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 241 Views

To split a string when the character value changes in JavaScript, you can use the match() method with a regular expression that captures consecutive identical characters. Syntax string.match(/(.)\1*/g) How the Regular Expression Works The pattern /(.)\1*/g breaks down as: (.) - Captures any single character \1 - Matches the same character as captured in group 1 * - Matches zero or more of the preceding element g - Global flag to find all matches Example var originalString = "JJJJOHHHHNNNSSSMMMIIITTTTHHH"; var regularExpression = /(.)\1*/g; console.log("The original string = ...

Read More

How can I use Web Workers in HTML5?

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

Web Workers allow for long-running scripts that are not interrupted by scripts that respond to clicks or other user interactions and allows long tasks to be executed without yielding to keep the page responsive. Web Workers are background scripts and they are relatively heavyweight and are not intended to be used in large numbers. For example, it would be inappropriate to launch one worker for each pixel of a four-megapixel image. Web Workers are initialized with the URL of a JavaScript file, which contains the code the worker will execute. This code sets event listeners and communicates with ...

Read More

Storing Credentials in Local Storage

Rishi Rathor
Rishi Rathor
Updated on 15-Mar-2026 1K+ Views

Local Storage is designed for data that spans multiple windows and persists beyond the current session. Web applications can store megabytes of user data on the client side for performance reasons. However, storing credentials requires special security considerations. For secure credential storage, never store actual passwords or sensitive authentication data directly in local storage. Instead, use a token-based approach that minimizes security risks. Secure Token-Based Authentication On successful login, generate a completely random token string unrelated to user credentials. Store this token in your database with an expiry date, then pass it to JavaScript for local storage. ...

Read More

How to display HTML5 client-side validation error bubbles?

Arjun Thakur
Arjun Thakur
Updated on 15-Mar-2026 401 Views

HTML5 provides built-in client-side validation with error bubbles that appear when users try to submit invalid form data. The required attribute and input types like email automatically trigger these validation messages. Basic Required Field Validation The required attribute prevents form submission if the field is empty and displays a validation bubble: HTML5 Validation Enter Email: ...

Read More

How not to validate HTML5 input with required attribute

Jennifer Nicholas
Jennifer Nicholas
Updated on 15-Mar-2026 257 Views

To avoid validation on specific form elements in HTML5, use the formnovalidate attribute on submit buttons or the novalidate attribute on the form itself. This allows you to bypass HTML5's built-in validation for required fields when needed. Using formnovalidate Attribute The formnovalidate attribute can be added to submit buttons to skip validation for that specific submission: HTML formnovalidate attribute Rank: ...

Read More

Update JavaScript object with another object, but only existing keys?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 973 Views

To update a JavaScript object with values from another object while only affecting existing keys, you can use hasOwnProperty() to check if a key exists in the source object before updating it. Example var markDetails1 = { 'marks1': 78, 'marks2': 65 }; var markDetails2 = { 'marks2': 89, 'marks3': 90 }; function updateJavaScriptObject(details1, details2) { const outputObject = {}; Object.keys(details1) .forEach(obj => outputObject[obj] ...

Read More

CSS content: attr() on HTML5 progress doesn't work

George John
George John
Updated on 15-Mar-2026 296 Views

The CSS content: attr() function doesn't work directly with HTML5 elements due to browser rendering limitations. Here's how to work around this issue. The Problem When you try to use content: attr() with progress elements, it fails because progress bars use special internal pseudo-elements that don't support generated content in the same way as regular elements. HTML Structure .progress-container { position: relative; ...

Read More

How to best display HTML5 geolocation accuracy on a Google Map?

Rishi Rathor
Rishi Rathor
Updated on 15-Mar-2026 486 Views

To display HTML5 geolocation accuracy on a Google Map, you need to combine the Geolocation API with Google Maps to show both the user's position and the accuracy radius as a circle. Basic Setup First, get the user's location using the HTML5 Geolocation API and extract the accuracy information: Geolocation Accuracy on Map function initMap() { ...

Read More

What HTML5 File.slice method actually doing?

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

The HTML5 Blob.slice() method creates a new Blob object containing a subset of data from the source Blob. It's particularly useful for processing large files in chunks or extracting specific portions of binary data. Syntax blob.slice(start, end, contentType) Parameters The slice() method accepts three optional parameters: start - Starting byte position (default: 0) end - Ending byte position (default: blob.size) contentType - MIME type for the new blob (default: empty string) Basic Example // Create a blob with text content var originalBlob = new ...

Read More

Simplest code for array intersection in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 218 Views

Array intersection finds common elements between two or more arrays. In JavaScript, the simplest approach uses filter() combined with includes(). Basic Example Let's find common elements between two arrays: var firstNamesArray = ["John", "David", "Bob", "Sam", "Carol"]; var secondNamesArray = ["Mike", "Carol", "Adam", "David"]; var intersectionOfArray = firstNamesArray.filter(v => secondNamesArray.includes(v)); console.log("Intersection of two arrays:"); console.log(intersectionOfArray); Intersection of two arrays: [ 'David', 'Carol' ] How It Works The filter() method creates a new array with elements that pass the test. For each element in ...

Read More
Showing 3581–3590 of 5,340 articles
« Prev 1 357 358 359 360 361 534 Next »
Advertisements