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
Front End Technology Articles
Page 289 of 652
How to create a dropdown list using JavaScript?
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 ...
Read MoreHow to create a dynamic length array with numbers and sum the numbers using JavaScript?
In JavaScript, arrays are always dynamic in length. Unlike some programming languages, we don't need to define the array's length while creating it. We can create an array and push whatever number of elements we want. Here, we will create a dynamic length array with numbers and sum all its elements. Using For Loop to Sum Array Elements We can iterate over the array using a for loop and add every element to get the sum. Let's look at both traditional for loops and for-of loops. Syntax let arraySum = 0; for (let i = ...
Read MoreHow to add a property to a JavaScript object using a variable as the name?
In JavaScript, you can add properties to objects using either dot notation or bracket notation. However, when you need to use a variable as the property name, bracket notation is the only viable approach. The Problem with Dot Notation Dot notation treats everything after the dot as a literal property name, not a variable: let obj = {a: "value1"}; let propertyName = "dynamicProp"; // This creates a property literally named "propertyName" obj.propertyName = "value2"; console.log(obj); console.log("Property 'dynamicProp' exists:", obj.dynamicProp); // undefined { a: 'value1', propertyName: 'value2' } Property 'dynamicProp' exists: undefined ...
Read MoreHow to Create Query Parameters in JavaScript?
Query parameters are key-value pairs appended to URLs after a question mark (?). They're essential for passing data between web pages, implementing search functionality, and creating dynamic URLs. For example, when you search on Amazon, your search term becomes a query parameter in the URL. JavaScript provides several methods to create query parameters programmatically. This is useful when building search features, filtering options, or any functionality that needs to modify URLs based on user input. Using encodeURIComponent() Method The encodeURIComponent() method encodes special characters in URL components. For example, spaces become %20, and other special characters are ...
Read MoreHow to calculate days left until next Christmas using JavaScript?
In this article, you will learn how to calculate the days remaining until the next Christmas using JavaScript. We'll use the Date object to work with dates and perform time calculations to determine how many days are left until December 25th. Understanding the Logic To calculate days until Christmas, we need to: Get today's date Determine the next Christmas date (this year or next year) Calculate the time difference in milliseconds Convert milliseconds to days Method 1: Direct Calculation In this approach, we calculate the time difference without using functions: let todayDate ...
Read MoreHow to access object properties from result returned by async() function in JavaScript?
In this article, you will understand how to access object properties from result returned by async() functions in JavaScript. An object property in JavaScript is a variable that is associated with the object itself, i.e. the properties have a name and value is one of the attributes linked with the property. When working with async functions that return objects, you can access their properties using standard JavaScript notation once the promise resolves. The key is using await to wait for the promise to resolve before accessing properties. Using Dot Notation In this example, let's understand how to ...
Read MoreHow to use array that include and check an object against a property of an object?
The task is to check whether the array contains a particular value. Also, we need to check if the array contains the particular object with the given property. This tutorial will use the array.includes() and array.some() methods to check whether the array contains the value or object with a particular property. Use the array.includes() method to check values exist in the array The array.includes() method allows us to check whether the array contains any value. In simple terms, we can search for values in the array using the array.includes() method. Syntax array.includes(value, startIndex); ...
Read MoreHow to add an element to a JSON object using JavaScript?
In this article, you will understand how to add an element to a JSON object using JavaScript. JSON objects are key-value pairs separated by colons and surrounded by curly braces {}. JavaScript provides two main ways to add new properties: bracket notation and dot notation. Using Bracket Notation Bracket notation is useful when property names contain special characters or are stored in variables. var jsonObject = { members: { host: "hostName", viewers: ...
Read MoreHow to calculate minutes between two dates in JavaScript?
In this article, you will understand how to calculate minutes between two dates in JavaScript. The Date object works with dates and times. Date objects are created with new Date(). To calculate minutes between dates, we convert the time difference from milliseconds to minutes using mathematical operations. Method 1: Using a Function In this example, we create a reusable function to find the time difference in minutes. function minutesDiff(dateTimeValue2, dateTimeValue1) { var differenceValue = (dateTimeValue2.getTime() - dateTimeValue1.getTime()) / 1000; differenceValue /= 60; return Math.abs(Math.round(differenceValue)); } ...
Read MoreHow to use await outside of an async function in JavaScript?
In JavaScript, the await keyword can only be used inside async functions. However, there are several techniques to work with asynchronous code when you need to use await at the top level or outside of async functions. Here, we will learn different approaches to handle asynchronous operations outside of regular async functions. Using Immediately Invoked Function Expression (IIFE) The most common approach is to wrap your code in an immediately invoked async function expression. This allows you to use await within the function scope. Syntax (async () => { let ...
Read More