Javascript Articles

Page 314 of 534

What is the importance of _.union() method in JavaScript?

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 1K+ Views

The _.union() method from the Underscore.js library creates a new array containing unique values from multiple input arrays. It performs a union operation, removing duplicates while preserving the original order of first occurrence. Syntax _.union(array1, array2, ...arrayN); Parameters array1, array2, ...arrayN: Two or more arrays to be combined. The method accepts any number of arrays as arguments. Return Value Returns a new array containing all unique values from the input arrays, maintaining the order of first occurrence. Example with Numbers In the following example, _.union() combines multiple arrays and removes ...

Read More

How to use JavaScript to replace the content of a document with JavaScript?

Abhishek
Abhishek
Updated on 15-Mar-2026 3K+ Views

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 More

How to get the application name and version information of a browser in JavaScript?

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 2K+ Views

JavaScript provides a navigator object that contains information about the browser. To get the application name and version information, the navigator object provides navigator.appName and navigator.appVersion properties respectively. Application Name of the Browser The navigator.appName property returns the application name of the browser. However, due to historical reasons, most modern browsers (Chrome, Firefox, Safari, Edge) return "Netscape" regardless of their actual name. Example document.write("Application Name: " + navigator.appName); Output Application Name: Netscape Browser Version Information The navigator.appVersion property provides ...

Read More

How to find the id of the form a button belongs to in JavaScript?

Abhishek
Abhishek
Updated on 15-Mar-2026 5K+ Views

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 More

How to find the text visible on the button with JavaScript?

Abhishek
Abhishek
Updated on 15-Mar-2026 10K+ Views

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 More

Using a JavaScript object inside a static() method?

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 135 Views

In JavaScript, static methods belong to the class itself, not to instances. You cannot directly access instance objects or use this inside static methods. However, you can pass objects as parameters to static methods to access their properties. Problem: Direct Object Access in Static Methods In the following example, trying to call a static method on an instance will result in an error because static methods should be called on the class, not the instance. class Company { constructor(branch) { ...

Read More

What records are present in JavaScript cookies?

Daniol Thomas
Daniol Thomas
Updated on 15-Mar-2026 258 Views

Your server sends some data to the visitor's browser in the form of a cookie. The browser may accept the cookie. If it does, it is stored as a plain text record on the visitor's hard drive. Now, when the visitor arrives at another page on your site, the browser sends the same cookie to the server for retrieval. Once retrieved, your server knows/remembers what was stored earlier. Cookies are a plain text data record of 5 variable-length fields − Cookie Fields Structure Name = Value − Cookies are set and retrieved in ...

Read More

Get the first and last item in an array using JavaScript?

Ayush Gupta
Ayush Gupta
Updated on 15-Mar-2026 369 Views

JavaScript arrays are 0-indexed, meaning the first element is at position 0 and the last element is at position length - 1. Here are several ways to access the first and last elements of an array. Using Index Access The most straightforward method uses bracket notation with index positions: let arr = [1, 'test', {}, 'hello', 42]; // First element console.log("First element:", arr[0]); // Last element console.log("Last element:", arr[arr.length - 1]); First element: 1 Last element: 42 Using Array Methods JavaScript provides built-in methods for accessing ...

Read More

How to get the id of a form containing a dropdown list with JavaScript?

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

In this tutorial, we will learn how to get the id of a form containing a dropdown list using JavaScript. The id property of an HTML element provides a unique identifier. The id property value must be unique within the HTML document. JavaScript uses it to access and manipulate elements with the specified id. A dropdown menu (also called a select element) provides a list of options where users can choose one item from multiple available options. Following are the methods to get the id of a form containing a dropdown list with JavaScript: Using the ...

Read More

How to select multiple options in a dropdown list with JavaScript?

Prabhdeep Singh
Prabhdeep Singh
Updated on 15-Mar-2026 12K+ Views

In JavaScript, you can enable multiple selection in a dropdown list by setting the multiple property to true. This allows users to select multiple options by holding Ctrl (Windows) or Cmd (Mac) while clicking. Syntax function enableMultipleSelection() { document.getElementById("selectId").multiple = true; } How It Works The multiple property controls whether a select element allows multiple selections. When set to true, users can select multiple options using keyboard modifiers: Ctrl + Click (Windows/Linux) to select multiple individual options Cmd + Click (Mac) to select multiple individual options Shift + Click ...

Read More
Showing 3131–3140 of 5,340 articles
« Prev 1 312 313 314 315 316 534 Next »
Advertisements