Javascript Articles

Page 106 of 534

Filter array with filter() and includes() in JavaScript

Revathi Satya Kondra
Revathi Satya Kondra
Updated on 28-Jan-2025 14K+ Views

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 suppose 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 the clear idea about the filter() and includes() in JavaScript. Let's discuss individually. JavaScript filter() and includes() Methods filter(): It is used to create a new array that includes only the elements that satisfy the condition provided by the callback function. includes(): Using includes(), the callback ...

Read More

How to Hide a div in JavaScript on Button Click?

AmitDiwan
AmitDiwan
Updated on 27-Jan-2025 6K+ Views

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 More

JavaScript Program to Find the average of all positive numbers in an array

AYUSH MISHRA
AYUSH MISHRA
Updated on 27-Jan-2025 6K+ Views

In this article, we will learn how to find the average of all positive numbers in an array using JavaScript, along with examples to demonstrate the implementation.  We are given an array of integers, which may contain both negative and positive numbers. Our task is to calculate the average of all the positive numbers in the array. Problem Description The goal is to compute the average of all positive numbers in a given array. This involves summing up the positive numbers and dividing the sum by the count of positive numbers. Input 1 arr = [2, -5, 6, -3, 8]; ...

Read More

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

Lokesh Yadav
Lokesh Yadav
Updated on 27-Jan-2025 3K+ Views

In this article we are going to learn how to find the action attribute and method of a form with suitable examples in JavaScript. In HTML, there is  elements which has few attributes: input, label, text area, select, name, target. The action and method attributes of the form are used to return those values. The action attribute also specifies where to send the form data when form is submitted. To get a better idea of this concept, let’s look into JavaScript examples where we achieved the given task using action attribute and also with method attribute. Using action ...

Read More

JavaScript program to find the average of all negative numbers in an array

AYUSH MISHRA
AYUSH MISHRA
Updated on 22-Jan-2025 6K+ Views

In this problem, we are given an array of integers, which may contain both negative and positive numbers. We have to find the average of all the negative numbers in the array. In this article, we are going to learn how we can find the average of all negative numbers in an array using JavaScript. Example 1 Input arr = [1, -3, 4, -2, -5]; Output -3.33 Explanation The negative numbers in the array are -3, -2, and -5. Their sum is -10, and the number of negative elements is 3. The average is: -10 / 3 = -3.33. ...

Read More

JavaScript Array Ranking

Alshifa Hasnain
Alshifa Hasnain
Updated on 22-Jan-2025 881 Views

In this article, we will learn to rank elements in arrays using JavaScript. Ranking elements in an array is common in various applications, such as sorting scores, evaluating performance, or analyzing data. What is Array Ranking? Array ranking involves assigning a rank to each element of an array based on its value, where the largest value gets the highest rank and the smallest value gets the lowest rank. This ranking can be extended to multiple arrays to analyze and compare data across different datasets. Problem Statement We are given multiple arrays of numbers. The task is to compute ranks for ...

Read More

JavaScript: How to return True if the focus is on the browser tab page?

Alshifa Hasnain
Alshifa Hasnain
Updated on 22-Jan-2025 2K+ Views

In this article, we will learn to check if the browser tab page is focused and under use or not in JavaScript. This is mainly required to record the user’s inactivity time on the app and then take any action upon it if required. Use Cases for Monitoring Browser Tab Focus Following are the use cases for monitoring browser tab focus and user inactivity − Prevent sending the network request if the page is not being used by the user as this would reduce the traffic on the server. This would ...

Read More

JavaScript: Adjacent Elements Product Algorithm

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 22-Jan-2025 922 Views

In this article, we will learn to calculate the adjacent elements product with the help of Javascript functionalities. This problem is often asked in coding interviews or algorithm challenges, and it tests one's understanding of array manipulation and performance optimization. Problem Statement Given an array of integers, your task is to return the largest product that can be obtained by multiplying any two adjacent numbers in the array. For example − Input [5, 1, 2, 3, 1] Output 6 The adjacent elements are (5, 1), (1, 2), (2, 3), and (3, 1). The largest product is 6 (from 2 * ...

Read More

JavaScript Program for Left Rotation and Right Rotation of a String

Shriansh Kumar
Shriansh Kumar
Updated on 21-Jan-2025 1K+ Views

To implement left rotation and right rotation of a string, we can use various approaches to implement this problem. Left rotation of a string means anti-clockwise movement of the given number of characters and right rotation of the string means clockwise movement of the given number of characters. In this article we are having a string and a value of k by which we will rotate the string. Our task is to write a JavaScript program for left rotation and right rotation of a string. Example Input: String str = "apple"; k = 3 Output: Left Rotation: ...

Read More

Create array from JSON object JavaScript

Alshifa Hasnain
Alshifa Hasnain
Updated on 20-Jan-2025 1K+ Views

In this article, we will learn to create an array from JSON data in JavaScript. JSON is a widely used format for storing and exchanging data. A common use case involves extracting specific data from a JSON object or array and converting it into a separate array for further processing. What is JSON Data? JSON (JavaScript Object Notation) is a lightweight data format commonly used to store and exchange data between a server and a client. It represents data as key-value pairs and is easy for both humans and machines to read and write. In JavaScript, JSON objects or arrays can be ...

Read More
Showing 1051–1060 of 5,338 articles
« Prev 1 104 105 106 107 108 534 Next »
Advertisements