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
How Do I Find the Largest Number in a 3D JavaScript Array?
To find the largest number in a 3D JavaScript array, we can use flat(Infinity) to flatten all nested levels, then apply Math.max() to find the maximum value. The Problem 3D arrays contain multiple levels of nested arrays, making it difficult to directly compare all numbers. We need to flatten the structure first. var theValuesIn3DArray = [75, [18, 89], [56, [97], [99]]]; Using flat() with Math.max() The flat(Infinity) method flattens all nested levels, and the spread operator ... passes individual elements to Math.max(). var theValuesIn3DArray = [75, [18, 89], [56, [97], [99]]]; ...
Read MoreResolving or rejecting promises accordingly - JavaScript
We are required to write a JavaScript function that imitates a network request, for that we can use the JavaScript setTimeout() function, that executes a task after a given time interval. Our function should return a promise that resolves when the request takes place successfully, otherwise it rejects Understanding Promise Resolution and Rejection When creating promises, we use the Promise constructor which takes an executor function with two parameters: resolve and reject. The resolve function is called when the operation succeeds, while reject is called when it fails. Example Following is the code that demonstrates ...
Read MoreDeleting the duplicate strings based on the ending characters - JavaScript
We are required to write a JavaScript function that takes in an array of strings and deletes each one of the two strings that ends with the same character. For example, if the actual array is: const arr = ['Radar', 'Cat', 'Dog', 'Car', 'Hat']; Then we have to delete duplicates and keep only one string ending with the same character. In this case, 'Cat', 'Car', and 'Hat' all end with 't', 'r', and 't' respectively, so we need to remove duplicates based on the last character. How It Works The algorithm uses a ...
Read MoreHow to clone a Date object in JavaScript?
In this tutorial, we will learn to clone a Date object in JavaScript. We can create a new object of the Date class that contains the date and time according to the user's requirement. Sometimes, it needs to copy the date, which means cloning it. In such cases, users can use the different approaches given below. Also, we will learn to set the new time and date in the cloned date in this tutorial. Using the Date.getTime() Method Users can simply create the new object of the Date class and get the total number of milliseconds from ...
Read MoreHow to get the largest integer less than or equal to a number in JavaScript?
In this tutorial, we will learn how to get the largest integer that can be less than or equal to a number in JavaScript. To get the largest integer less than or equal to a number, we use the Math.floor() method in JavaScript. It rounds down a number to its nearest integer towards the lower value, regardless of the decimal portion. Following are two ways to find the largest integer that can be less than or equal to a number in JavaScript. Using Math.floor() Method The Math.floor() method returns the greatest integer that is less than ...
Read MoreHow to create many Javascript variables in a single statement?
We can create many JavaScript variables in a single statement using the var, let, and const keywords. Instead of declaring every variable individually, we can chain many variables together with commas (, ) in a single statement. Since JavaScript is a loosely typed language, variables of different data types can be declared in the same sentence as well. Syntax var variable1 = value1, variable2 = value2, variable3 = value3; let variable1 = value1, variable2 = value2, variable3 = value3; const variable1 = value1, variable2 = value2, variable3 = value3; Using var Keyword The var ...
Read MoreWhat is the role of altKey Mouse Event in JavaScript?
The altKey property of mouse events in JavaScript indicates whether the Alt key was pressed when a mouse button was clicked. This property returns a boolean value: true if the Alt key was held down, false otherwise. Syntax event.altKey Return Value Returns true if the Alt key was pressed during the mouse event, false if it was not pressed. Example The following example demonstrates how to detect whether the Alt key was pressed during a mouse click: Press and hold ALT key and ...
Read MoreSplitting and uploading extremely large files to Amazon S3
When dealing with extremely large files (10+ GB), uploading directly to Amazon S3 can be challenging due to network timeouts and bandwidth limitations. Amazon S3's multipart upload feature provides a robust solution by splitting large files into smaller chunks that can be uploaded independently and in parallel. How Multipart Upload Works The process involves three main steps: Initiate: Start a multipart upload session with S3 Upload Parts: Split the file into chunks and upload each part independently Complete: Combine all parts into the final object ...
Read MoreCreating a BinaryTree using Javascript
A Binary Search Tree (BST) is a hierarchical data structure where each node has at most two children. Let's learn how to create and represent a binary search tree in JavaScript by building a complete BST class with essential operations. Basic Structure We'll start by creating the BinarySearchTree class and defining a Node class for individual tree elements. class BinarySearchTree { constructor() { // Initialize a root element to null this.root = null; ...
Read MoreHow to get a particular anchor in a document in JavaScript?
In this article we will learn how to get a particular anchor in a document in JavaScript. JavaScript provides multiple ways to access anchor elements ( tags) in a document. Anchor elements follow an array-like structure, allowing you to select specific anchors by index or use DOM methods to retrieve them. There are two primary methods to get a particular anchor element: using document.anchors collection or document.getElementsByTagName("a") method. Syntax The syntax to get a particular anchor tag is shown below: // Method 1: Using document.anchors collection document.anchors[index].innerHTML // Method 2: Using getElementsByTagName document.getElementsByTagName("a")[index].innerHTML ...
Read More