AmitDiwan

AmitDiwan

8,392 Articles Published

Articles by AmitDiwan

Page 407 of 840

Find the element that appears once in sorted array - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 619 Views

Suppose, we have a sorted array of literals like this − const arr = [2, 2, 3, 3, 3, 5, 5, 6, 7, 8, 9]; We are required to write a JavaScript function that takes in one such array and returns the first number that appears only once in the array. If there is no such number in the array, we should return false. For this array, the output should be 6 Approach 1: Linear Scan with State Tracking This approach uses a boolean flag to track whether we've encountered duplicates of the ...

Read More

What's the best way to open new browser window using JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 311 Views

The window.open() method is the standard way to open new browser windows in JavaScript. It provides control over window features and behavior. Syntax window.open(url, name, features) Parameters url: The URL to open (optional) name: Window name or target (optional) features: Window features like size, position, toolbar (optional) Basic Example Open New Window body { ...

Read More

How to find the one integer that appears an odd number of times in a JavaScript array?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 270 Views

We are given an array of integers and told that all the elements appear for an even number of times except a single element. Our job is to find that element in single iteration. Let this be the sample array: [1, 4, 3, 4, 2, 3, 2, 7, 8, 8, 9, 7, 9] Understanding XOR Operator Before attempting this problem, we need to understand a little about the bitwise XOR (^) operator. The XOR operator returns TRUE if both the operands are complementary to each other and returns FALSE if both the operands ...

Read More

How to toggle between password visibility with JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 263 Views

To toggle between password visibility with JavaScript, you can change the input type between "password" and "text" using a checkbox or button. This allows users to see their password when needed. How It Works The toggle functionality works by: Adding an event listener to a checkbox or button Checking the current input type Switching between "password" and "text" types Example: Using Checkbox Toggle Password Toggle Example Password Visibility Toggle ...

Read More

JavaScript multiline Property

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 215 Views

The JavaScript multiline property is a read-only property of regular expression objects that returns true if the 'm' modifier (multiline flag) has been set, and false otherwise. The 'm' flag changes the behavior of ^ and $ anchors to match at line breaks within the string. Syntax regexp.multiline Return Value Returns a boolean value: true if the 'm' flag is set false if the 'm' flag is not set Example: Checking multiline Property ...

Read More

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

Title Case A Sentence JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 331 Views

Let's say we are required to write a function that accepts a string and capitalizes the first letter of every word in that string and changes the case of all the remaining letters to lowercase. For example, if the input string is — hello world coding is very interesting The output should be — Hello World Coding Is Very Interesting Let's define a function capitaliseTitle() that takes in a string and capitalises the first letter of each word and returns the string — Using Split and Map Method ...

Read More

JavaScript merge multiple Boolean arrays with the OR || operator

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 700 Views

There are times when you need to merge multiple Boolean arrays into a single array in JavaScript. One common approach is to combine the corresponding elements from each array using the OR (||) operator. This operation returns true if at least one of the elements being compared is true; otherwise, it returns false. In this article, we'll learn how to merge multiple Boolean arrays into a single array using JavaScript, specifically by applying the OR operator on corresponding elements. Problem Definition We are given an array of arrays of Boolean values, like this: Input: const ...

Read More

Check for Subarray in the original array with 0 sum JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 505 Views

We are required to write a JavaScript function that takes in an array of Numbers with some positive and negative values. We are required to determine whether there exists a subarray in the original array whose net sum is 0 or not. Our function should return a boolean on this basis. Approach The approach here is simple. We iterate over the array using a for loop, calculate the cumulative sum up to that particular element. And if any point the cumulative becomes 0 or attains a value it has previously attained, then there exists a subarray with ...

Read More

How to create a form with multiple steps in JavaScript?

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

Creating multi-step forms improves user experience by breaking complex forms into manageable sections. This approach reduces form abandonment and makes data collection more organized. Complete Multi-Step Form Example Here's a complete implementation of a multi-step registration form with validation and progress indicators: * { box-sizing: border-box; } body { background-color: #f1f1f1; } #regForm { margin: 100px auto; ...

Read More
Showing 4061–4070 of 8,392 articles
« Prev 1 405 406 407 408 409 840 Next »
Advertisements