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
Articles by AmitDiwan
Page 407 of 840
Find the element that appears once in sorted array - JavaScript
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 MoreWhat's the best way to open new browser window using JavaScript?
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 MoreHow to find the one integer that appears an odd number of times in a JavaScript array?
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 MoreHow to toggle between password visibility with JavaScript?
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 MoreJavaScript multiline Property
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 MoreHow to disable future dates in JavaScript Datepicker?
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 MoreTitle Case A Sentence JavaScript
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 MoreJavaScript merge multiple Boolean arrays with the OR || operator
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 MoreCheck for Subarray in the original array with 0 sum JavaScript
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 MoreHow to create a form with multiple steps in JavaScript?
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