Javascript Articles

Page 495 of 534

JavaScript merge multiple Boolean arrays with the OR || operator

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 701 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

JavaScript Submit textbox on pressing ENTER?

Alshifa Hasnain
Alshifa Hasnain
Updated on 15-Mar-2026 3K+ Views

In this article, we will learn to Submit a textbox by pressing ENTER in JavaScript. Submitting a textbox form by pressing the ENTER key is a common requirement in web development, enhancing the user experience by making interactions smoother and more intuitive. Why Enable Form Submission on ENTER Key Press? Allowing users to submit a form by pressing the ENTER key is an efficient way to enhance usability and reduce friction in the user interface. Whether you're building a search bar, login form, or any other type of text input, implementing this feature saves time and makes interactions ...

Read More

JavaScript map value to keys (reverse object mapping)

Alshifa Hasnain
Alshifa Hasnain
Updated on 15-Mar-2026 1K+ Views

In JavaScript, there are scenarios where we need to reverse the mapping of keys and values in an object, creating a new object where the original values become keys, and the keys become their corresponding values. For example, cities can be grouped by their states. In this article, we'll learn two approaches to achieve this: using Object.keys with iteration and reduce. Using Object.keys() with forEach The first approach involves iterating over the keys of the original object using Object.keys() of Object properties and populating a new object. If multiple keys in the original object share the same value, ...

Read More

How can I round a number to 1 decimal place in JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 34K+ Views

In this tutorial, we will learn to round a number to a one decimal place in JavaScript. There are various needs to round the float numbers and show particular digits after the decimal point. In our case, we need to show only one digit after the decimal point. However, we will create a customizable function that can round off the number and show the particular number of digits after the decimal point at the end of this tutorial. This example lets users understand the fundamental need to round a number to a single decimal digit. Suppose you are ...

Read More

JavaScript - convert array with null value to string

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 678 Views

In this article, we will learn to convert an array with a null value to a string in Javascript. Handling arrays containing null, undefined, and falsy values in JavaScript is a frequent challenge. The default methods might not behave as expected when converting such arrays to strings, requiring custom solutions for meaningful string representations. Problem Statement Given an array containing null, undefined, empty strings, and other values, the task is to concatenate its elements into a single string while excluding the unwanted values. Following is our array, with some null and undefined values − Input ...

Read More

JavaScript: How to loop through all DOM elements on a page and display result on console?

Alshifa Hasnain
Alshifa Hasnain
Updated on 15-Mar-2026 1K+ Views

In this article, we will learn how to iterate through all DOM elements on a webpage using JavaScript. By doing so, we can easily access and manipulate various elements of the page, whether for debugging, gathering information, or applying changes to the page's structure and content. We'll walk through a step-by-step process to loop through all elements and display the results in the console, helping you better understand how to interact with the DOM. What is the DOM? The Document Object Model (DOM) is a representation of the structure of a webpage. It treats each part of the ...

Read More

JavaScript equivalent of Python\'s zip function

Alshifa Hasnain
Alshifa Hasnain
Updated on 15-Mar-2026 1K+ Views

In this article, we will learn the JavaScript equivalent of Python's zip function. In Python, the zip() function is a convenient way to combine multiple arrays into a single iterable of tuples. However, JavaScript does not have a built-in equivalent for this functionality, so we need to implement our own. Problem Statement Given two or more arrays of equal length, implement a function in JavaScript that combines these arrays into a single array of arrays, where each inner array contains the elements from the input arrays at ...

Read More

JavaScript Narcissistic number

Alshifa Hasnain
Alshifa Hasnain
Updated on 15-Mar-2026 938 Views

In this article, we will learn to check if a number is Narcissistic in JavaScript. A Narcissistic number is a number that equals the sum of its digits, each raised to the power of the total number of digits. We will explore two approaches to solve this problem: an iterative method and a concise string manipulation technique. What is a Narcissistic Number? A narcissistic number (also known as an Armstrong number) in a given number base is a number that equals the sum of its digits each raised to the power of the number of digits. For ...

Read More

JavaScript Program to Check if a Given Year is Leap Year

Shriansh Kumar
Shriansh Kumar
Updated on 15-Mar-2026 2K+ Views

To check if a given year is leap year, we have used two approaches in this article. A leap year has 366 days. In every 4th year, an additional day is added to the month of February to synchronize it with the astronomical year. In this article, we are given with two years to check. Our task is to write a JavaScript program to check if a given year is leap year. Leap Year Rules A year is considered a leap year if it follows these rules: Divisible by 4 AND not divisible ...

Read More

How to Find the action Attribute and method of a Form in JavaScript?

Lokesh Yadav
Lokesh Yadav
Updated on 15-Mar-2026 3K+ Views

In HTML forms, the action and method attributes control where form data is sent and how it's transmitted. JavaScript provides properties to access and modify these attributes dynamically. The action attribute specifies the URL where form data should be sent when submitted, while the method attribute determines the HTTP method used for submission (GET, POST, or dialog). Using the action Property The action property allows you to get or set the form's action attribute value. Syntax // Get action attribute let actionValue = document.getElementById('formID').action; // Set action attribute document.getElementById('formID').action = 'newURL'; ...

Read More
Showing 4941–4950 of 5,340 articles
« Prev 1 493 494 495 496 497 534 Next »
Advertisements