Articles on Trending Technologies

Technical articles with clear explanations and examples

Tutorix - AI Tutor

Get n numbers from array starting from given point JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 346 Views

We need to create a custom Array method that extracts n elements from an array starting at a given index, moving in a specified direction (left or right). When we reach array boundaries, the function wraps around to continue from the other end. Problem Requirements The function should take three parameters: n - number of elements to extract m - starting index (must be ≤ array.length - 1) direction - either 'left' or 'right' For example, if we have [0, 1, 2, 3, 4, 5, 6, 7] and call get(4, 6, 'right'), it should return ...

Read More

Display whether the office is closed or open right now on the basis of current time with JavaScript ternary operator

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 449 Views

Let's say we are matching the current date and time with the business hours. We need to display whether the office is closed or open right now on the basis of current time. We can get the current hour from the Date object and use the JavaScript ternary operator to determine if the office is open or closed based on business hours. Syntax const currentHour = new Date().getHours(); const status = (condition) ? 'Open' : 'Closed'; Example Office ...

Read More

Sum all duplicate value in array - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 543 Views

We are required to write a JavaScript function that takes in an array of numbers with duplicate entries and sums all the duplicate entries to one index. For example − If the input array is − const input = [1, 3, 1, 3, 5, 7, 5, 4]; Then the output should be − const output = [2, 6, 7, 10, 4]; Using Map to Track and Sum Duplicates The most efficient approach is to use a Map to count occurrences and then multiply each unique value by its count: ...

Read More

Adding two values at a time from an array - JavaScript

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

Let's say, we are required to write a JavaScript function that takes in an array of Numbers and returns a new array with elements as sum of two consecutive elements from the original array. For example, if the input array is − const arr = [3, 6, 3, 87, 3, 23, 2, 2, 6, 8]; Then the output should be − const output = [9, 90, 26, 4, 14]; Example Following is the code − const arr = [3, 6, 3, 87, 3, 23, 2, 2, 6, 8]; ...

Read More

How to search the alternate text of an image-map area in JavaScript?

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

To search the alternate (alt) text of an image-map area in JavaScript, use the alt property. This property allows you to access or modify the alternative text that describes the image map area for accessibility purposes. Syntax // Get alt text let altText = areaElement.alt; // Set alt text areaElement.alt = "new alt text"; Example: Accessing Alt Text of Image Map Area ...

Read More

Does HTML5 allow you to interact with local client files from within a browser?

varun
varun
Updated on 15-Mar-2026 470 Views

HTML5 allows web applications to interact with local client files through powerful APIs. These interfaces enable browsers to access the user's file system, read binary data, and handle file operations that were previously impossible with standard web technologies. HTML5 File APIs HTML5 provides three main APIs for file interaction: File API - Read file contents and metadata File System API - Access file system structure (deprecated in modern browsers) File Writer API - Write data to files (limited browser support) Reading Local Files The ...

Read More

How to check if a document is ready in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 868 Views

In JavaScript, you can check if the DOM is fully loaded using document.readyState or event listeners. This is crucial for ensuring your scripts run after the HTML structure is ready. Understanding document.readyState The document.readyState property has three possible values: "loading" - The document is still loading "interactive" - The document has loaded but resources like images may still be loading "complete" - The document and all resources have finished loading Method 1: Using document.readyState Document Ready ...

Read More

How to find a group of three elements in an array whose sum equals some target sum JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 691 Views

We need to write a function that finds three elements in an array whose sum equals a target value. The function should return the indices of these three elements, or -1 if no such triplet exists. Approach We'll use a two-step approach: Create a twoSum() helper function that finds two numbers adding up to a target sum Iterate through each element and use twoSum() to find the remaining two elements This approach has O(N²) time complexity, where N is the array length. How It Works The twoSum() function uses a hash map ...

Read More

Find unique and biggest string values from an array in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 321 Views

In JavaScript, we often need to filter arrays to get unique values and sort them by specific criteria. This article demonstrates how to find the longest unique string values from an array of objects. Problem Statement Given an array of objects with text properties, we need to create a function that returns n objects with the longest unique string values. If fewer than n unique objects exist, return all unique objects. const arr = [ {text: 'use'}, {text: 'secur'}, {text: 'form'}, ...

Read More

Create new array without impacting values from old array in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 361 Views

In JavaScript, directly assigning an array to a new variable creates a reference to the original array, not a copy. This means changes to the new variable will affect the original array. To create a truly independent copy, you need to use specific cloning methods. The Problem with Direct Assignment When you assign an array directly, both variables point to the same array in memory: var originalArray = ["John", "Mike", "Sam", "Carol"]; var newArray = originalArray; // This creates a reference, not a copy newArray.push("David"); console.log("Original array:", originalArray); console.log("New array:", newArray); ...

Read More
Showing 18491–18500 of 61,298 articles
Advertisements