Articles on Trending Technologies

Technical articles with clear explanations and examples

How to update an object with setState in ReactJS?

Rushi Javiya
Rushi Javiya
Updated on 15-Mar-2026 2K+ Views

In React, state objects store component data that can change over time. This tutorial covers how to update state objects using both class components with setState() and functional components with hooks. Using setState() in Class Components The setState() method is used to update state in class components. When updating nested objects, use the spread operator to preserve other properties. Syntax this.setState({ student: { ...this.state.student, fees: new_value, }, }); Example: Updating Simple State Object This example shows how to update a ...

Read More

Web Components: Building Custom Elements with JavaScript

Mukul Latiyan
Mukul Latiyan
Updated on 15-Mar-2026 607 Views

Web components are a powerful tool for building reusable and encapsulated UI elements in web applications. They allow developers to create custom elements with their own markup, style, and behavior, which can be easily reused across different projects and shared with other developers. In this article, we will explore the fundamentals of web components and learn how to build custom elements using JavaScript. What are Web Components? Web components are a set of web platform APIs that allow you to create reusable, encapsulated, and composable UI elements. They consist of three main specifications: Custom Elements, Shadow DOM, and ...

Read More

How to Trim White Spaces from input in ReactJS?

Rushi Javiya
Rushi Javiya
Updated on 15-Mar-2026 7K+ Views

We will learn to trim white spaces from the input in ReactJS. Sometimes, users add unnecessary space at the start or end of the input by mistake. So, as a developer, we need to check if the input string contains the white space at the start or end. If we find white spaces in the input, we should trim it; Otherwise, it can cause issues. For example, we need to store the email in the database, and while registering the email, the user has also added the white spaces by mistake, and we stored the email in the database ...

Read More

JavaScript Program to Find the average of all positive numbers in an array

AYUSH MISHRA
AYUSH MISHRA
Updated on 15-Mar-2026 6K+ Views

In this article, we will learn how to find the average of all positive numbers in an array using JavaScript, along with examples to demonstrate the implementation. We are given an array of integers, which may contain both negative and positive numbers. Our task is to calculate the average of all the positive numbers in the array. Problem Description The goal is to compute the average of all positive numbers in a given array. This involves summing up the positive numbers and dividing the sum by the count of positive numbers. Example 1 Input: ...

Read More

JavaScript Program to Find Area of a Circle

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

To find area of a circle using JavaScript, we will be using the simple formula: Area = π × r² where r is the radius and π is a constant value pi. In this article, we are having radius of the circle and our task is to find the area of the circle using JavaScript. r center Area = π × r² Example Calculation let radius = 10 and π(pi) = ...

Read More

JavaScript Program for Maximize Elements Using Another Array

Prabhdeep Singh
Prabhdeep Singh
Updated on 15-Mar-2026 292 Views

In this article, we are going to implement a JavaScript program for maximizing elements using another array. We are given two arrays and have to pick some elements from the second array and replace the elements of the first array to maximize the sum. Problem Statement In this problem, we are given two arrays and we have to make all the elements of the first array as large as possible by replacing them with elements from the second array. Each element from the second array can only be used once. The goal is to maximize the sum of ...

Read More

How to create an array with multiple objects having multiple nested key-value pairs in JavaScript?

Tarun Singh
Tarun Singh
Updated on 15-Mar-2026 6K+ Views

JavaScript is a versatile language that is widely used for creating dynamic web applications. One of the most common data structures used in JavaScript is the array. An array is a collection of elements that can be of any type, including objects. In this article, we will discuss how to create an array with multiple objects having multiple nested key-value pairs in JavaScript. What are arrays? An array is a special type of object that stores a collection of values. These values can be of any data type, such as numbers, strings, booleans, and even other arrays. Arrays ...

Read More

How to validate a Date in ReactJS?

Rushi Javiya
Rushi Javiya
Updated on 15-Mar-2026 4K+ Views

Sometimes, we require to take the date from the users in string format. Users can make mistakes while entering the date value into the input field, so we need to validate the date string in our application code. Below, we will learn various solutions to validate dates in ReactJS. Using the Validator NPM Package The Validator is an NPM package that contains various methods to validate strings. It includes the isDate() method to validate date strings with any delimiter. It also contains methods to validate emails and phone numbers. Use the below command to install the ...

Read More

How to Validate an Email in ReactJS?

Rushi Javiya
Rushi Javiya
Updated on 15-Mar-2026 7K+ Views

Email validation is an important feature we need to add to authentication forms. Nowadays, most applications use email and a one-time password for authentication. If the user enters the wrong email, they should not be able to authenticate themselves. Also, we need to validate the email while getting the user's email via contact forms. The user may enter the wrong email format due to some mistake. To correct users' mistakes, we can alert them by showing an error message. Below, we will learn two approaches to validate email addresses in ReactJS using different methods. Using the validator ...

Read More

JavaScript Program for Maximum Product Subarray

Prabhdeep Singh
Prabhdeep Singh
Updated on 15-Mar-2026 440 Views

A subarray is a contiguous portion of an array. In the maximum product subarray problem, we need to find the subarray whose elements have the largest product when multiplied together. This is a classic dynamic programming problem with interesting edge cases involving negative numbers and zeros. Problem Analysis The challenge becomes complex when dealing with different types of numbers: All positive numbers: The entire array gives maximum product Contains zeros: Array splits into segments at zero positions Contains negative numbers: Even count of negatives gives positive product, ...

Read More
Showing 14321–14330 of 61,297 articles
Advertisements