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
Javascript Articles
Page 495 of 534
JavaScript map value to keys (reverse object mapping)
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 MoreHow can I round a number to 1 decimal place in JavaScript?
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 MoreJavaScript - convert array with null value to string
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 MoreJavaScript: How to loop through all DOM elements on a page and display result on console?
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 MoreJavaScript equivalent of Python\'s zip function
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 MoreJavaScript Narcissistic number
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 MoreJavaScript Program to Check if a Given Year is Leap Year
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 MoreHow to Find the action Attribute and method of a Form in JavaScript?
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 MoreHow to Hide a div in JavaScript on Button Click?
To hide a div in JavaScript on button click we will be discussing three different approaches with example codes. We will hide the div upon clicking the button and similarly display the hidden div upon clicking the button. In this article we are having a div element. Our task is to hide the div on clicking the button using JavaScript. Approaches to Hide div on Button Click Here is a list of approaches to hide a div in JavaScript on button click which we will be discussing in this article with stepwise explanation and complete example codes. ...
Read MoreFilter array with filter() and includes() in JavaScript
In this article, using the filter() and includes() methods in JavaScript, we can filter an array based on the elements presence in another array or specific conditions. For example, if we have two arrays as array1 and array2, we want to filter array1 to include only the elements that are present in array2. To have a clear idea about the filter() and includes() methods in JavaScript, let's discuss them individually. JavaScript filter() and includes() Methods filter(): Creates a new array that includes only the elements that satisfy the condition provided by the callback function. includes(): ...
Read More