In JavaScript, arrays are always dynamic in length. Like other programming languages, we don’t need to define the array's length while creating the array. So, we can create an array and push whatever number of elements we want in the JavaScript array. Here, we will create the dynamic length of the array and add numbers to that. After that, we will sum up all numbers. This tutorial will teach us to create a dynamic length array with numbers and sum the numbers using JavaScript. Use the for loop to sum all elements of the dynamic array We can iterate over ... Read More
We will learn to create a dropdown list using HTML and JavaScript below. Before starting with the article, let’s understand the dropdown list and why we need to use it. The dropdown list gives multiple choices to users and allows them to select one value from all options. However, we can do the same thing using multiple radio buttons, but what if we have hundreds of choices? Then we can use the dropdown menu. When users click the dropdown button, it opens all the choices, and users can select anyone. Also, the dropdown provides a better user experience than the ... Read More
In this article, you will understand how to add float numbers using JavaScript. Float values in JavaScript are defined as parseFloat(string). Example 1 In this example, let’s understand adding float values without using functions. let inputFloat1 = parseFloat(2.3) let inputFloat2 = parseFloat(3.5) console.log("The two float values are defined as ", inputFloat1 ,"and", inputFloat2) let result = inputFloat1 + inputFloat2 console.log("The sum of the float values is: ", result) Explanation Step 1 − Define two float values inputFloat1 and inputFloat2. Step 2 − Add the two float values using addition operator (+). Step 3 − Display the result. ... Read More
In this article, you will understand how to add a parameter to the URL in JavaScript. There are two methods to add parameters to an url: append() method and set() method. The append() method is used to specifically add key-value pairs to the url. The set() method adds the value to a specific key. If the key doesn't exist, a new key is created. If several keys exist, the value is updated for one of them and others are deleted. Example 1 Let's look at the append() method in this example let inputUrl = new URL('https://urlExample.com?key1=value1'); let inputParams = new ... Read More
The dialog box is a popup box like a modal in ReactJS. In vanilla JavaScript, maybe you have used the alert() method, which allows us to show an alert message in the alert box. Also, vanilla JavaScript provides the confirm box and prompt box to take user input. The dialog box also allows us to perform all operations. We can add the normal HTML to the dialog box according to our requirements, and it works as a popup box. In this tutorial, we will use the various libraries to create a dialog box. Use the Material-Ui library The Material-Ui library ... Read More
The date picker allows users of the application to pick a date. If we take data in the string format from the users, they can make a mistake while entering the date and enter the wrong format of the date. So, the best way to take a correct date input from the users is using the date picker. In this tutorial, we will use various libraries of ReactJS and create a date picker allowing users to pick any date, month, year, or decade. Use the ‘react-date-picker’ NPM package The react provides various libraries and npm packages to manipulate the date ... Read More
In this article, you will understand how to access the first value of an object using JavaScript. The first value of the object is the first property located at position[0] of the object. The object can be a key-value object or an array object. Example 1 In this example, let's consider a key-value pair object. const inputObject = {1: 'JavaScript', 2: 'Python', 3: 'HTML'}; console.log("A key-value pair object is defined and its values are: ", inputObject) console.log("The first value of the object is: ") const firstValue = Object.values(inputObject)[0]; console.log(firstValue); Explanation Step 1 − Define a key-value pair ... Read More
In JavaScript, the object contains various properties and methods. For every property, it contains a value. We need to compare the values of the property also to make the comparison between two objects. Here, we will learn to check if the first object contains all properties that the second object contains and compare the values for every property. Compare the object property values one by one The easiest way is to check for every property of the second object that the first object contains or not. If the first object contains that property, compare the values of both. It means ... Read More
In this article, you will understand how to access an object having spaces in the object’s key using JavaScript. In such cases, we use bracket notation ‘[]’ to access objects or we use dot notation(.) to access objects. Let’s see a few examples below. Example 1 In this example, let's use the bracket notation[] to access objects. console.log("The input object is a key value pair with key as firstName and value as Joseph"); const inputObject = {'firstName': 'Joseph'}; console.log("Using bracket notation to access value") console.log(inputObject['firstName']); console.log("Using bracket notation to change the value to Alice") inputObject['firstName'] = 'Alice'; ... Read More
In this article, you will understand how optional chaining works in TypeScript. Optional chaining operator (?.) accesses an object’s property. If the objects property is null or not defined, it returns ‘undefined’. Let us first understand what TypeScript is. Strongly typed programming language TypeScript, which is based on JavaScript, gives you better tools at any scale. Code written in TypeScript can be converted to execute in any JavaScript-compatible environment. JavaScript is understood by TypeScript, and type inference is used to provide excellent tooling without the need for additional code. Example 1 In this example, we use the optional chaining operator ... Read More