Web Development Articles

Page 428 of 801

How to disable future dates in JavaScript Datepicker?

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

Disabling future dates in a JavaScript datepicker prevents users from selecting dates beyond today. This is commonly needed for applications like booking systems, report generators, or any form where only past or current dates are valid. Understanding the maxDate Property The maxDate property sets the maximum selectable date in a datepicker. By setting it to the current date, all future dates become disabled and unclickable. Example: jQuery UI Datepicker ...

Read More

From an array of arrays, return an array where each item is the sum of all the items in the corresponding subarray in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 360 Views

Given an array of arrays, each of which contains a set of numbers. We have to write a function that returns an array where each item is the sum of all the items in the corresponding subarray. For example, if we have nested arrays with numbers, we want to calculate the sum of each inner array and return those sums as a new array. Example Input and Expected Output If the input array is: const numbers = [ [1, 2, 3, 4], [5, 6, 7], [8, ...

Read More

How to disable default behavior of when you press enter with JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 401 Views

To disable the default behavior when the Enter key is pressed, you need to use the keydown event listener along with preventDefault(). This prevents the browser from executing its default action for the Enter key. How It Works The preventDefault() method cancels the default action that belongs to the event. When combined with checking for the Enter key (event.key === "Enter"), it stops the browser's default behavior like form submission or input validation. Example Disable Enter Key Default ...

Read More

Find the longest sub array of consecutive numbers with a while loop in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 404 Views

We are required to write a function with a while-statement that determines the length of the largest consecutive subarray in an array of positive integers. For instance, if we have an array like [6, 7, 8, 6, 12, 1, 2, 3, 4], the longest consecutive sequence is [1, 2, 3, 4] with length 4. Problem Understanding Let's look at some examples to understand the problem better: Input: [6, 7, 8, 6, 12, 1, 2, 3, 4] Consecutive sequence: [1, 2, 3, 4] Output: 4 Input: [5, 6, 1, 8, 9, 7] Consecutive ...

Read More

How can I disable JavaScript click function if link starts with #?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 479 Views

In JavaScript, you can disable click functionality for links that start with "#" using preventDefault() and CSS selectors. This technique prevents hash links from executing click handlers while allowing normal links to work. Problem Sometimes you need to apply click handlers to most links but exclude hash links (href="#") that are used for navigation or placeholder purposes. Solution Using jQuery Use the :not() selector to exclude links with href="#" from the click handler: Disable Hash Link Clicks ...

Read More

Unicode Property Escapes JavaScript Regular Expressions

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 265 Views

Unicode property escapes in JavaScript regular expressions allow you to match characters based on their Unicode properties using the u flag. This feature enables precise matching of characters by their Unicode categories, scripts, or properties. Syntax /\p{PropertyName}/u /\P{PropertyName}/u // Negated form The \p{} matches characters with the specified property, while \P{} matches characters WITHOUT that property. Common Unicode Properties Property Description Example Characters Letter Any letter A, B, α, β, 中 Number Any number 1, 2, ①, ② Emoji_Presentation Emoji characters 😀, 🌟, 🎉 ...

Read More

Simplifying nested array JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 437 Views

Let's say, we have an array of arrays that contains some elements like this − const arr = [3, 5, 7, 2, [4, NaN, null, 4, 8, [3, undefined, 24, null], null, 5, 1], NaN, 45, 2, 1]; Our job is to write a recursive function that takes in this nested array and replaces all the falsy values inside the array (NaN, undefined and null) with 0. Understanding Falsy Values In JavaScript, falsy values include: null undefined NaN ...

Read More

Lookbehind Assertions JavaScript Regular Expressions

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 208 Views

Lookbehind assertions in JavaScript regular expressions allow you to match a pattern only when it's preceded by a specific pattern. They use the syntax (? Syntax // Positive lookbehind - match if preceded by pattern (?Example: Extracting Prices with Positive Lookbehind This example matches numbers that are preceded by a dollar sign: Lookbehind Assertions The prices are $50, $99, $121 and $150. But 25 and 75 are not prices. Extract Prices ...

Read More

Nearest palindrome in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 795 Views

We are required to write a function that takes in a number n and returns a palindromic number that is nearest to the number n. A palindrome reads the same forwards and backwards. For example: If the input number is 264, then the output should be 262 If the input number is 7834, then the output should be 7887 Approach The approach divides the number into two halves based on its length and creates a palindrome by mirroring the first half. For odd-length numbers, the middle digit remains unchanged. Example const ...

Read More

Named capture groups JavaScript Regular Expressions

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 234 Views

Named capture groups in JavaScript regular expressions allow you to assign names to captured groups, making your code more readable and maintainable. Instead of accessing groups by index, you can reference them by meaningful names. Syntax // Named capture group syntax /(?pattern)/ // Accessing named groups match.groups.name Basic Example Named Capture Groups const text = "The year I graduated was 2012."; ...

Read More
Showing 4271–4280 of 8,010 articles
« Prev 1 426 427 428 429 430 801 Next »
Advertisements