Articles on Trending Technologies

Technical articles with clear explanations and examples

Alternatively merging two arrays - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 861 Views

We are required to write a JavaScript function that takes in two arrays and merges the arrays taking elements alternatively from the arrays. For example, if the two arrays are: const arr1 = [4, 3, 2, 5, 6, 8, 9]; const arr2 = [2, 1, 6, 8, 9, 4, 3]; Then the output should be: const output = [4, 2, 3, 1, 2, 6, 5, 8, 6, 9, 8, 4, 9, 3]; Method 1: Using Index-Based Logic This approach uses a single loop and alternates between arrays based on even/odd ...

Read More

How to serialize a JavaScript array?

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

In JavaScript, serializing an array means converting it into a string format that can be stored, transmitted, or reconstructed later. While jQuery's serializeArray() method is useful for form data, JavaScript provides native methods for general array serialization. What is Array Serialization? Array serialization converts a JavaScript array into a string representation. The most common approach uses JSON.stringify() to convert arrays into JSON strings, which can be easily transmitted to servers or stored in local storage. Using JSON.stringify() (Recommended) The JSON.stringify() method is the standard way to serialize JavaScript arrays: // Simple array serialization let ...

Read More

How to get the arccosine (in radians) of a number in JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 357 Views

This tutorial will help you to find the arccosine in radians of a number in JavaScript. Cosine is the ratio of the adjacent side and the hypotenuse of the right-angled triangle. To get the cosine of a number, the Math.cos() function is used in JavaScript. The value returned will be between -1 and 1. The inverse of cosine is called arccosine. An angle's trigonometric arccosine value can be calculated using the Math.acos() method. This returns a value between 0 and π (pi). The input to acos() must be between -1 and 1 inclusive. The function returns the ...

Read More

How to define custom JavaScript exceptions?

V Jyothi
V Jyothi
Updated on 15-Mar-2026 242 Views

Custom JavaScript exceptions allow you to create specific error types for your application. You can throw custom error messages or create custom error classes for better error handling. Basic Custom Exception with String The simplest way to create a custom exception is by throwing a string message: function divide(a, b) { try { ...

Read More

What is the usage of onreset event in JavaScript?

Anjana
Anjana
Updated on 15-Mar-2026 457 Views

The onreset event is triggered when a form is reset using a reset button or the reset() method. This event allows you to execute JavaScript code when users clear form data. Syntax // form elements // Or using addEventListener form.addEventListener('reset', functionName); Example: Basic onreset Event onreset Event Example function resetFunct() { alert("The form was ...

Read More

How to set the list-item marker type with JavaScript?

Fendadis John
Fendadis John
Updated on 15-Mar-2026 539 Views

To set the type of the list-item marker, use the listStyleType property in JavaScript. This property allows you to change bullet styles for unordered lists and numbering styles for ordered lists. Syntax element.style.listStyleType = "value"; Common List Style Types Here are the most commonly used marker types: Value Description Best for disc Filled circle (default) Unordered lists circle Empty circle Unordered lists square Filled square Unordered lists decimal Numbers (1, 2, 3...) Ordered lists upper-roman Uppercase Roman (I, II, III...) Ordered ...

Read More

Detection on clicking bezier path shape with HTML5

Ankith Reddy
Ankith Reddy
Updated on 15-Mar-2026 278 Views

To detect clicks on Bezier path shapes in HTML5 Canvas, you need to use pixel-based detection since Canvas doesn't have built-in shape hit testing. This technique draws the shape invisibly and checks if the clicked pixel contains color data. How Pixel-Based Detection Works The method involves drawing the Bezier shape to a hidden canvas context, then checking if the clicked coordinates contain any pixels. If the alpha channel is greater than 0, the click hit the shape. Complete Click Detection Example const canvas = document.getElementById('myCanvas'); const ctx = canvas.getContext('2d'); // Sample Bezier ...

Read More

Loop through a Dictionary in Javascript

Monica Mona
Monica Mona
Updated on 15-Mar-2026 12K+ Views

In JavaScript, a dictionary (or object) stores key-value pairs. There are several ways to loop through these pairs depending on whether you're working with plain objects, ES6 Maps, or custom implementations. Method 1: Using for...in Loop (Plain Objects) The for...in loop is the traditional way to iterate through object properties: const dictionary = { key1: "value1", key2: "value2", key3: "value3" }; for (let key in dictionary) { console.log(`Key: ${key}, Value: ${dictionary[key]}`); } Key: key1, Value: value1 ...

Read More

How to identify the nth sub element using xpath?

Debomita Bhattacharjee
Debomita Bhattacharjee
Updated on 15-Mar-2026 7K+ Views

We can identify the nth sub element using xpath in the following ways: By adding square brackets with index. By using position() method in xpath. Method 1: Using Square Brackets with Index The most common approach is to add square brackets with the desired index number after the element selector: // Select the 2nd div element //div[2] // Select the 3rd li element inside ul //ul/li[3] // Select the first input with type='text' //input[@type='text'][1] Method 2: Using position() Function The position() function provides another way to target elements ...

Read More

How to create a multidimensional JavaScript object?

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

A multidimensional JavaScript object is an object that contains other objects as properties, creating nested structures. This allows you to organize complex data hierarchically. Basic Syntax let multidimensionalObject = { property1: "value1", property2: { nestedProperty1: "nestedValue1", nestedProperty2: { deeplyNestedProperty: "deeplyNestedValue" } } }; Example: Creating a Student ...

Read More
Showing 18021–18030 of 61,297 articles
Advertisements