Articles on Trending Technologies

Technical articles with clear explanations and examples

The Dictionary Class in Javascript

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

JavaScript doesn't have a built-in Dictionary class, but we can create our own using objects or the Map class. Here's a complete implementation of a custom Dictionary class called MyMap. Complete Dictionary Implementation class MyMap { constructor() { this.container = {}; } display() { console.log(this.container); } hasKey(key) { return key in this.container; } ...

Read More

Looping over matches with JavaScript regular expressions

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 962 Views

In JavaScript, you can loop over regular expression matches using several methods. The most common approaches are using match() with the global flag, matchAll(), or exec() in a loop. Using match() with Global Flag The match() method with the global flag (g) returns an array of all matches, which you can then iterate over: Regex Matches Loop body { ...

Read More

How to assign values to an array with null/empty objects in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 976 Views

In JavaScript, you can assign values to an array containing null or empty objects using various methods. This is useful when you need to populate placeholder objects with actual data. Method 1: Using forEach() with Object.keys() This approach iterates through an array of empty objects and assigns properties from a source object: Assign Values to Empty Objects Assign values to an array with null/empty objects Assign Values ...

Read More

Find the shortest string in an array - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 798 Views

We are required to write a JavaScript function that takes in an array of strings and returns the shortest string in the array. This is a common programming problem that can be solved efficiently using different approaches. We will explore multiple methods to find the shortest string, from simple loops to functional programming approaches. Using for Loop The most straightforward approach uses a for loop to iterate through the array and track the shortest string: const arr = ['this', 'can', 'be', 'some', 'random', 'sentence']; function findShortestString(strings) { if (strings.length === ...

Read More

How to pass an object as a parameter in JavaScript function?

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

In this tutorial, we will learn how to pass an object as a parameter in a JavaScript function. One of JavaScript's data types is represented by the Object type. It is used to store keyed collections as well as more complex entities. The Object() constructor or the object initializer / literal syntax can be used to create objects. Almost all JavaScript objects are instances of Object; a typical object inherits properties (including methods) from Object.prototype, though these properties may be shadowed (a.k.a. overridden). Following are the methods used to pass an object as a parameter in a ...

Read More

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

Lakshmi Srinivas
Lakshmi Srinivas
Updated on 15-Mar-2026 2K+ Views

In JavaScript, you can set the top margin of an element using the marginTop property. This property allows you to dynamically modify the spacing above an element, making it useful for responsive layouts and interactive designs. Syntax element.style.marginTop = "value"; The value can be specified in various CSS units like pixels (px), percentages (%), em, rem, etc. Example #myID { border: 2px solid #000000; ...

Read More

HTML5 Video Tag in Chrome - Why is currentTime ignored when video downloaded from my webserver?

Chandu yadav
Chandu yadav
Updated on 15-Mar-2026 644 Views

The HTML5 video tag's currentTime property may not work properly in Chrome when your web server doesn't support HTTP range requests (byte-range serving). Chrome requires this feature for video seeking functionality. The Problem When you set currentTime on a video element, Chrome needs to jump to that specific time position in the video file. Without range request support, the browser cannot efficiently seek to arbitrary positions, causing currentTime to be ignored. Testing Your Web Server Check if your server supports byte-range requests using curl: curl --dump-header - -r0-0 http://yourserver.com/video.mp4 Look for this ...

Read More

Hash Table Data Structure in Javascript

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

Hash Table is a data structure which stores data in an associative manner. In a hash table, data is stored in an array format, where each data value has its own unique index value. Access to data becomes very fast if we know the index of the desired data. Thus, it becomes a data structure in which insertion and search operations are very fast irrespective of the size of the data. Hash Table uses an array as a storage medium and uses the hash technique to generate an index where an element is to be inserted or is to ...

Read More

Retrieve element from local storage in JavaScript?

Lokesh Yadav
Lokesh Yadav
Updated on 15-Mar-2026 7K+ Views

To retrieve elements from local storage in JavaScript, we use the localStorage.getItem() method. Local storage provides persistent client-side data storage that remains available even after closing the browser. Local storage is a web API that allows you to store key-value pairs in a user's browser. Unlike session storage, data in local storage persists until explicitly removed or cleared by the user. This makes it ideal for storing user preferences, application state, or cached data. Local Storage Methods Local storage provides four main methods for data management: setItem(key, value) - Stores a key-value ...

Read More

Can we convert two arrays into one JavaScript object?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 256 Views

In JavaScript, you can convert two arrays into a single object by using one array as keys and another as values. This is useful when you have related data stored in separate arrays. Using forEach() Method The most common approach is to use forEach() to iterate through the keys array and map each key to its corresponding value: Convert Arrays to Object Convert Two Arrays into One JavaScript Object ...

Read More
Showing 18041–18050 of 61,297 articles
Advertisements