Articles on Trending Technologies

Technical articles with clear explanations and examples

Split one-dimensional array into two-dimensional array JavaScript

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

We are required to write a function that takes in a one-dimensional array as the first argument and a number n as the second argument and we have to make n subarrays inside of the parent array (if possible) and divide elements into them accordingly. If the array contains 9 elements and we asked to make 4 subarrays, then dividing 2 elements in each subarray creates 5 subarrays and 3 in each creates 3, so in such cases we have to fallback to nearest lowest level (3 in ...

Read More

Split string into equal parts JavaScript

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

In JavaScript, splitting a string into equal parts can be accomplished in several ways. This article demonstrates how to split a string into n equal parts using an alternating pattern that takes characters from both ends of the string. Problem Statement We need to write a JavaScript function that takes a string and a number n as arguments, where n exactly divides the string length. The function should return an array of n strings of equal length, formed by alternating between the first and last characters of the remaining string. For example: If the string ...

Read More

Sum of distinct elements of an array - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 554 Views

We are required to write a JavaScript function that takes in one such array and counts the sum of all distinct elements of the array. For example: Suppose, we have an array of numbers like this − const arr = [1, 5, 2, 1, 2, 3, 4, 5, 7, 8, 7, 1]; The distinct elements are: 1, 5, 2, 3, 4, 7, 8. Their sum is: 1 + 5 + 2 + 3 + 4 + 7 + 8 = 30. Using lastIndexOf() Method This approach checks if the current index matches the ...

Read More

How to remove leading zeros from a number in JavaScript?

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

In this tutorial, we will explore how we can remove leading zeroes from any number in JavaScript. JavaScript removes leading zeroes from an integer variable automatically, but this is not the case when we consider strings in JavaScript. It is possible that a string in JavaScript which represents a numerical value may contain leading zeroes. These leading zeroes may cause problems when we try to perform any operation on the numerical value the string represents. This is why we will explore the ways by which we can remove the leading zeroes from a number, expressed as a string in ...

Read More

How to merge two arrays in JavaScript?

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

In this tutorial, we will learn how to merge two arrays in JavaScript. In JavaScript, we can merge two arrays using different approaches. Here are the three most common methods: Using the Array concat() method Using the spread operator Using loop iteration Using the Array concat() Method The Array concat() method merges two or more arrays and returns a new array. This is one of the most popular methods for merging arrays in JavaScript. The method operates on an array, takes another array as a ...

Read More

How to set the image to be used as a border with JavaScript?

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

In this tutorial, we will learn how to set the image to be used as a border with JavaScript. The outline of an HTML element is called the border. The 'border-image' CSS property is used to set an image as the border around an element. It is a shorthand property for: border-image-source, border-image-slice, border-image-width, border-image-outset, border-image-repeat. To set the image to be used as a border with JavaScript we have different ways − Using the style.borderImage Property Using the style.setProperty Method Using the style.borderImage Property An element's ...

Read More

How can I write a form that assists my browser's auto-complete feature?

Krantik Chavan
Krantik Chavan
Updated on 15-Mar-2026 174 Views

HTML forms can leverage browser autocomplete to improve user experience by providing appropriate hints about what data each field expects. The autocomplete attribute tells browsers how to pre-fill form fields based on previously entered data. The autocomplete Attribute The HTML5 specification defines the autocomplete attribute to help browsers understand field purposes. When set to "on", browsers use heuristics based on field names, DOM position, and other factors to suggest appropriate values. Common Autocomplete Values Use specific autocomplete values to provide clear hints to browsers: Field Name Meaning "name" Full name ...

Read More

Usage of CSS border-spacing property

Lakshmi Srinivas
Lakshmi Srinivas
Updated on 15-Mar-2026 85 Views

The border-spacing CSS property controls the distance between adjacent table cell borders. It only applies to tables with border-collapse: separate and accepts one or two length values. Syntax border-spacing: horizontal vertical; border-spacing: value; /* applies to both directions */ Parameters One value: Sets equal spacing horizontally and vertically Two values: First value sets horizontal spacing, second sets vertical spacing Units: Any CSS length unit (px, em, rem, etc.) Example: Different Spacing Values table { ...

Read More

Atomics.xor() function in JavaScript

Samual Sam
Samual Sam
Updated on 15-Mar-2026 202 Views

The Atomic object of JavaScript is an object that provides atomic operations such as add, sub, and, or, xor, load, store etc. as static methods. These methods are used with SharedArrayBuffer objects for thread-safe operations in multi-threaded environments. The xor() function of the Atomics object accepts an array, position, and value, then performs a bitwise XOR operation on the value at the given position atomically. Syntax Atomics.xor(typedArray, index, value) Parameters typedArray - A shared integer typed array (Int8Array, Uint8Array, Int16Array, etc.) index - The position in the array to operate on value ...

Read More

Using a JavaScript object inside a static() method?

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 134 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
Showing 11831–11840 of 61,303 articles
Advertisements