Articles on Trending Technologies

Technical articles with clear explanations and examples

Compare array elements to equality - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 713 Views

In JavaScript, you can compare array elements at corresponding positions to count how many values match. This is useful for analyzing similarities between two arrays in a sequence-dependent manner. For example, if you have two arrays: const arr1 = [4, 7, 4, 3, 3, 3, 7, 6, 5]; const arr2 = [6, 5, 4, 5, 3, 2, 5, 7, 5]; The function should compare arr1[0] with arr2[0], arr1[1] with arr2[1], and so on. In this case, positions 2, 4, and 7 have matching values, so the result is 3. Using a For Loop ...

Read More

How to convert a string into upper case using JavaScript?

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

In JavaScript, converting strings to uppercase is a common task needed for data validation, form processing, and ensuring consistent text formatting. JavaScript provides a built-in method for this purpose, and you can also create custom implementations to understand the underlying mechanism. This tutorial covers different approaches to convert strings to uppercase, from the standard built-in method to creating custom functions for educational purposes. Using the String toUpperCase() Method The toUpperCase() method is the most straightforward way to convert strings to uppercase. It's a built-in JavaScript method that works on any string value and returns a new string ...

Read More

Which event occurs in JavaScript when a dragged element is dropped?

Swarali Sree
Swarali Sree
Updated on 15-Mar-2026 245 Views

The ondrop event occurs when a dragged element is successfully dropped on a valid drop target. This event is part of the HTML5 Drag and Drop API and must work together with ondragover to enable dropping functionality. How Drag and Drop Works The drag and drop process involves several events: ondragstart - When dragging begins ondragover - When dragged element is over a drop target ondrop - When element is dropped on target ondragend - When dragging operation ends Key Requirements For ondrop to work properly: The drop target must handle ondragover and ...

Read More

How to set the top padding of an element with JavaScript?

Priya Pallavi
Priya Pallavi
Updated on 15-Mar-2026 688 Views

Use the paddingTop property in JavaScript to set the top padding of an element. This property allows you to dynamically modify the spacing between an element's content and its top border. Syntax element.style.paddingTop = "value"; Where value can be specified in pixels (px), percentages (%), or other CSS units. Example #box { border: 2px solid #FF0000; ...

Read More

How to display JavaScript variables in an HTML page without document.write?

Sravani S
Sravani S
Updated on 15-Mar-2026 584 Views

Use Element.innerHTML in JavaScript to display JavaScript variables in an HTML page without document.write(). This approach provides better control over content placement and doesn't overwrite the entire page. Basic Example: Displaying Variables Here's how to display JavaScript variables using innerHTML: Display Variables User Information Name: Age: City: // JavaScript variables ...

Read More

How to keep audio playing while navigating through pages?

Samual Sam
Samual Sam
Updated on 15-Mar-2026 1K+ Views

To keep audio playing while navigating through pages, you need to prevent full page reloads that would interrupt playback. Here are the main approaches: Method 1: Using AJAX with History API Load new content dynamically without refreshing the page using AJAX combined with the History API's pushState() method. Continuous Audio Example ...

Read More

Join Map values into a single string with JavaScript?

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

In JavaScript, a Map stores key-value pairs where each key is unique. To join all Map values into a single string, you can use Array.from() to convert Map values to an array, then apply join() methods. Basic Approach The process involves three steps: extract values from the Map, flatten nested arrays, and join them into a string. let queryStringAppendWithURL = new Map(); queryStringAppendWithURL.set("firstParameter", ["name=John", "age=23", "countryName=US"]); queryStringAppendWithURL.set("secondParameter", ["subjectName=JavaScript", "Marks=91"]); let appendValue = Array.from(queryStringAppendWithURL.values()) .map(value => value.join('&')) .join('&'); console.log("The appended value is: " + appendValue); ...

Read More

Getting HTML form values and display on console in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 6K+ Views

In JavaScript, you can retrieve HTML form values using the value property of form elements. This is essential for processing user input and form data. Basic Syntax To get a form element's value, use: document.getElementById("elementId").value Example: Getting Input Value Here's how to get a text input value and display it in the console: Get Form Values ...

Read More

How to run a function after two async functions complete - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 2K+ Views

When working with multiple asynchronous operations in JavaScript, you often need to wait for all of them to complete before executing a final function. This is a common scenario in web development where you might be fetching data from multiple APIs or processing several files concurrently. There are several approaches to handle this challenge, with Promise.all() being the most efficient for running multiple async operations concurrently. Using Promise.all() (Recommended) Promise.all() executes multiple promises concurrently and waits for all of them to resolve. It's the optimal choice when you need all operations to complete regardless of their individual ...

Read More

Why is [1,2] + [3,4] = "1,23,4" in JavaScript?

Arjun Thakur
Arjun Thakur
Updated on 15-Mar-2026 149 Views

The JavaScript's + operator is used to add two numbers or join two strings. However, when used with arrays, it doesn't concatenate them as you might expect. Instead, it converts both arrays to strings and then concatenates those strings. What Happens with [1, 2] + [3, 4] When JavaScript encounters the + operator between two arrays, it follows these steps: Convert each array to a string using the toString() method Concatenate the resulting strings // Step 1: Arrays are converted to strings console.log([1, 2].toString()); // "1, 2" console.log([3, 4].toString()); // "3, ...

Read More
Showing 16661–16670 of 61,297 articles
Advertisements