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 Abhishek
Page 3 of 7
How to find the min/max element of an Array in JavaScript?
In JavaScript, finding the minimum and maximum elements of an array is a common task. The minimum element is the smallest value in the array, while the maximum is the largest. This tutorial covers the most effective approaches to accomplish this. There are two main approaches to find min/max elements: Manual traversal using loops Using Math.min() and Math.max() methods Method 1: Manual Array Traversal This approach involves iterating through the entire array and comparing each element to keep track of the minimum and maximum values. It ...
Read MoreHow to find duplicate values in a JavaScript array?
In this tutorial, we will discuss how we can find duplicate or repeating values in a JavaScript array using different methods or approaches to reach the solution to this problem. Below is the list of the approaches or methods we can use to solve the problem of finding duplicates − By simply Traversing the Array Using the filter() and indexOf() Methods Using the Set object and has() Method Let us discuss all of the above approaches to find duplicates in the JavaScript array − By Simply Traversing the Array Traversing the array using ...
Read MoreHow to turn JavaScript array into the comma-separated list?
In this tutorial, we will learn how we can change the elements of a JavaScript array in a comma-separated list. Sometimes, we need the elements of a JavaScript array in a format that is not returned by the array itself by default, so we need to write some extra code to implement this task. Fortunately, JavaScript allows us to do so by using some in-built methods. We will discuss these methods in detail. Following are the in-built methods provided by JavaScript to convert the array into a comma-separated list − Array join() method ...
Read MoreHow to find the name of the first form in a document with JavaScript?
In this tutorial, we will learn how to find the name of the first form in an HTML document. Sometimes, we use more than one form tags in the HTML document for different purposes. At that time, we can face difficulties in finding the specific element to add some more properties to it. In such conditions, we can use the forms property of the "document" interface to access all the elements present in the document individually as well as collectively. Document.forms Property As we discussed above, the forms property is used to access all the forms ...
Read MoreHow to find the number of anchors with JavaScript?
In this tutorial, we will learn how to count the number of anchor elements ( tags) in an HTML document using JavaScript. The document.anchors property provides a way to access all anchors with a name attribute in the document. Note: The document.anchors property is deprecated and only counts anchors with a name attribute. For modern development, use document.querySelectorAll('a') instead. Using document.anchors (Deprecated) The document.anchors property returns an HTMLCollection containing all anchor elements that have a name attribute. You can use the length property to get the count. Syntax let anchors = document.anchors; let numberOfAnchors ...
Read MoreHow to stop form submission using JavaScript?
In this tutorial, we will see the methods to stop form submission using JavaScript. Generally, the HTML form by default submits automatically when certain events are triggered. The automatic submission causes the browser to refresh and reload the whole page, which we don't want in some cases. To perform any operation before submission, we need to change the default behavior of the form to prevent it from submitting. Following are the methods we can use to stop form submission: Using the "return false" value Using the preventDefault() method Let ...
Read MoreHow to use JavaScript to replace the content of a document with JavaScript?
In this tutorial, we will learn how to use JavaScript to replace the entire content of an HTML document. JavaScript provides three document methods that work together to achieve this: open(), write(), and close(). The Three Methods document.open() − Opens a new document stream for writing. It takes two optional parameters: the MIME type (typically "text/html") and "replace" to replace the current document's history entry. document.write() − Writes content to the document stream. ...
Read MoreHow to find the id of the form a button belongs to in JavaScript?
In this tutorial, we will learn how we can find the id of the form element to which a button belongs using JavaScript. In HTML, we can use button tag in two ways with form tag, where it can be used to perform some activity in the form when it is clicked, as listed below − Button is inside the FORM tag Button is outside the FORM tag No matter where the button is located, whether it is inside or outside, we can find the ID of the form tag ...
Read MoreHow to find the text visible on the button with JavaScript?
In this tutorial, we will discuss different approaches to find the text visible on the button with JavaScript. The text on a button shows what will happen if you click the button. To extract the text on the button, JavaScript provides us with the following two properties. Using the innerHTML Property Using the innerText Property Let us discuss both of the above properties in detail. Using the innerHTML Property The innerHTML property not only allows us to get the text inside any tag but also allows us to set the text ...
Read MoreHow to split JavaScript Number into individual digits?
In this tutorial, we will learn how to split a JavaScript number into individual digits. This technique is useful for tasks like checking palindrome numbers, finding digit sums, or analyzing number patterns. We'll explore three different approaches based on the input format: Using modulo operator for numeric input Using array push() method for string input Using string split() method for string input Method 1: Using Modulo Operator (Numeric Input) When the input is a number, we can use the modulo (%) operator with division to extract digits from right to left. Syntax ...
Read More