Articles on Trending Technologies

Technical articles with clear explanations and examples

Garbage collection(GC) in JavaScript?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 2K+ Views

Memory management in JavaScript is much easier than in low-level languages like C or C++. Unlike low-level languages, JavaScript automatically detects which objects will be needed in later cases and which will be garbage that is occupying memory without any reason. In this article, we shall discuss how garbage collection (GC) works in JavaScript. There are a few important parts that we are going to discuss in detail: Reachability from root Interlinked Objects (interconnections between different objects) Unreachable Collections (Broken link) Reachability The first concept of ...

Read More

Sorting arrays by two criteria in JavaScript

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

When sorting arrays by multiple criteria in JavaScript, you need to create a custom comparator function that handles each condition sequentially. This article demonstrates sorting objects by priority (isImportant) first, then by date within each priority group. The Array Structure Consider an array of objects with id, date, and isImportant properties. We want important items first, then sort by date within each group: const array = [{ id: 545, date: 591020824000, isImportant: false, }, { id: 322, ...

Read More

Filter array of objects by a specific property in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 622 Views

Filtering arrays of objects by specific properties is a common task in JavaScript. While the article shows using map() with a ternary operator for comparison, the filter() method is typically more appropriate for filtering operations. Basic Array Filtering with filter() The filter() method creates a new array with elements that pass a test condition: let customers = [ {firstName: 'John', amount: 100}, {firstName: 'David', amount: 50}, {firstName: 'Bob', amount: 80}, {firstName: 'Alice', amount: 120} ]; // Filter customers with ...

Read More

Split a URL in JavaScript after every forward slash?

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

To split a URL in JavaScript, use the split() method with a forward slash (/) as the delimiter. This breaks the URL into an array of segments. Syntax url.split("/") Basic Example var newURL = "http://www.example.com/index.html/homePage/aboutus/"; console.log("Original URL:", newURL); var splitURL = newURL.split("/"); console.log("Split URL:", splitURL); Original URL: http://www.example.com/index.html/homePage/aboutus/ Split URL: [ 'http:', '', 'www.example.com', 'index.html', 'homePage', 'aboutus', '' ] Understanding the Output The result contains empty strings because: Index 0: 'http:' ...

Read More

Checking an array for palindromes - JavaScript

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

We are required to write a JavaScript function that takes in an array of String / Number literals and returns a subarray of all the elements that were palindrome in the original array. A palindrome is a word, number, or sequence that reads the same forward and backward. For example, "dad", "racecar", and 12321 are palindromes. Problem Statement If the input array is: const arr = ['carecar', 1344, 12321, 'did', 'cannot']; Then the output should be: const output = [12321, 'did']; Approach We will create a helper function ...

Read More

How to find the min/max element of an Array in JavaScript?

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

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 More

How to set the capitalization of a text with JavaScript?

Ramu Prasad
Ramu Prasad
Updated on 15-Mar-2026 296 Views

To set the capitalization, use the textTransform property in JavaScript. Set it to capitalize, if you want the first letter of every word to be a capital letter. Syntax element.style.textTransform = "value"; The textTransform property accepts these values: capitalize - Capitalizes the first letter of each word uppercase - Converts all text to uppercase lowercase - Converts all text to lowercase none - Removes any text transformation Example: Capitalizing Text You can try to run the following code to capitalize text with JavaScript: ...

Read More

How to convert the image into a base64 string using JavaScript?

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

To convert an image into a base64 string using JavaScript, you can use the FileReader API for local files or combine XMLHttpRequest with FileReader for remote images. Base64 encoding represents binary image data as a text string, making it useful for embedding images directly in HTML or CSS. Method 1: Converting Local Image Files For user-uploaded files, use the FileReader API with an input element: document.getElementById('imageInput').addEventListener('change', function(e) { ...

Read More

Sorting by 'next' and 'previous' properties (JS comparator function)

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 438 Views

When working with linked data structures in JavaScript, you may encounter objects that reference each other through 'next' and 'previous' properties. This tutorial demonstrates how to sort such objects into their correct sequential order. Problem Statement Consider an array of objects representing pages of a website, where each object has: An id property for unique identification A next property pointing to the next page's id (unless it's the last page) A previous property pointing to the previous page's id (unless it's the first page) These objects are randomly positioned in the array, and we need ...

Read More

Any way to solve this without concatenating these two arrays to get objects with higher value?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 91 Views

To find objects with higher property values from two arrays without concatenation, use the reduce() method on both arrays individually. This approach compares objects by a specific property and keeps only those with the highest values. Problem Setup Consider two arrays containing student objects with names and marks from different sections: var sectionAStudentDetails = [ {studentName: 'John', studentMarks: 78}, {studentName: 'David', studentMarks: 65}, {studentName: 'Bob', studentMarks: 98} ]; let sectionBStudentDetails = [ {studentName: 'John', studentMarks: 67}, ...

Read More
Showing 16721–16730 of 61,297 articles
Advertisements