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
Javascript Articles
Page 496 of 534
JavaScript - Converting array of objects into object of arrays
In this article, we will learn to convert an array of objects into an object of arrays in JavaScript. When working with JavaScript, it's common to handle arrays of objects representing structured data. A frequent challenge is grouping these objects based on a shared property and transforming the result into a new data structure. Problem Statement The goal is to convert an array of objects into an object of arrays where the keys represent a specific property (e.g., roles) and the values are arrays of corresponding data (e.g., player names). Input const team = [ ...
Read MoreWhat is the difference between JavaScript undefined and void(0)?
In this article, we will learn the difference between JavaScript undefined and void(0). Though they may appear similar, they serve distinct purposes and can be used in different scenarios. What is JavaScript undefined? undefined means a variable declared, but no value has been assigned. It is a primitive value automatically assigned to variables that have been declared but not initialized. For Example − var demo; console.log(demo); // shows undefined console.log(typeof demo); // shows undefined undefined undefined It is a global property that represents a variable ...
Read MoreJavaScript Basic Array Methods
In this article, we will learn about different basic array methods in JavaScript. These methods allow you to manipulate, search, and transform arrays effectively. Adding and Removing Elements JavaScript provides several methods to add and remove elements from arrays: Method Description ...
Read MoreJavaScript code to find nth term of a series - Arithmetic Progression (AP)
To find the nth term of an arithmetic progression in JavaScript, we need to write a function that calculates the nth term using the AP formula. In this article, we will explore how to find the nth term of an AP using JavaScript. We are required to write a JavaScript function that takes three parameters: the first two consecutive terms of an arithmetic progression, and the position n of the term we want to find. If the input is 2, 5, 7 (first term = 2, second term = 5, position = 7): Then the series will ...
Read MoreJavaScript to push value in empty index in array
To push value in an empty index in an array, we can create a custom method that finds the first empty slot and fills it, or appends to the end if no empty slots exist. Arrays in JavaScript can have empty slots (also called sparse arrays) where certain indexes are undefined. When working with such arrays, you might need to fill these gaps before adding new elements at the end. Understanding Empty Slots in Arrays Empty slots occur when you skip indexes during array creation or deletion: const arr = [1, 2, , 4, , ...
Read MoreJavaScript Prompt Example
In this article, we will learn to use the prompt() function in Javascript. The prompt() method in JavaScript allows developers to collect user input through a pop-up dialog box. What is the prompt() Method in JavaScript? The prompt dialog box is very useful when you want to pop-up a text box to get user input. Thus, it enables you to interact with the user. The user needs to fill in the field and then click OK. This dialog box is displayed using a method called prompt(). Syntax var userInput = prompt("Message", "Default value"); ...
Read MoreJavaScript ArrayBuffer Object
In this article, we will learn about JavaScript ArrayBuffer objects. The ArrayBuffer object in JavaScript is a fundamental part of the Web API for efficiently handling binary data. What is ArrayBuffer? The JavaScript ArrayBuffer object represents a generic, fixed-length raw binary data buffer. To manipulate the contents of an ArrayBuffer object we have to create a DataView object as we cannot manipulate the contents directly. We can read and write both using the DataView object. Syntax new ArrayBuffer(byteSize) The byteSize parameter specifies the array buffer size in bytes that will be created. ...
Read MoreJavaScript - Remove first n characters from string
In JavaScript, removing the first n characters from a string is a common operation when processing text data. There are several efficient methods to accomplish this task. What is String Character Removal? Removing the first n characters from a string means creating a new string that excludes the specified number of characters from the beginning. For example Input − const str = "JavaScript"; const n = 4; Output − Script Different Approaches The following are the different approaches to remove the first n characters from a string ...
Read MoreJavaScript regex program to display name to be only numbers, letters and underscore.
In this article, we will learn the regex program to validate names to contain only numbers, letters, and underscores in JavaScript. Validating user input is essential for maintaining data integrity and security in web applications. JavaScript Regex for Name Validation Regular expressions (regex) are powerful tools for defining patterns to search and validate text. A common validation requirement is ensuring a name consists only of letters (A-Z, a-z), digits (0-9), and underscore (_). To ensure that a name contains only allowed characters, we use the following regex pattern: /^\w+$/ Regex Pattern Breakdown ...
Read MoreJavaScript focus a particular element with div class, not div id declaration?
In this article, we will learn to focus on a particular element with a div class in JavaScript. In JavaScript, setting focus on an element is commonly done using the focus() method, which works with elements selected by class name. What is the focus() method? The focus() method in JavaScript is used to bring a specific element into focus. This means the element becomes active, allowing the user to interact with it, such as typing in an input field or highlighting a section of the webpage. Syntax element.focus(); Here, the element is the ...
Read More