Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles on Trending Technologies
Technical articles with clear explanations and examples
The Dictionary Class in Javascript
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 MoreLooping over matches with JavaScript regular expressions
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 MoreHow to assign values to an array with null/empty objects in JavaScript?
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 MoreFind the shortest string in an array - JavaScript
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 MoreHow to pass an object as a parameter in JavaScript function?
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 MoreHow to set the top margin of an element with JavaScript?
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 MoreHTML5 Video Tag in Chrome - Why is currentTime ignored when video downloaded from my webserver?
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 MoreHash Table Data Structure in Javascript
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 MoreRetrieve element from local storage in JavaScript?
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 MoreCan we convert two arrays into one JavaScript object?
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