Get Requests Using AJAX with Custom HTTP Library

Shubham Vora
Updated on 16-Feb-2023 15:35:28

259 Views

We will learn to make a get request using the AJAX by making the custom HTTP library. Let’s learn about the Get request and AJAX before we start with the tutorial. The Get request is used to get or fetch data from the API (Application programming interface). The AJAX stands for Asynchronous JavaScript and XML. The AJAX allows us to load or update new data without reloading the webpage. For example, if you have ever worked with ReactJs, it updates the data without reloading the webpage. If we reload the webpage whenever data updates, it can give a bad user ... Read More

Use Checkbox Inside Select Option Using JavaScript

Shubham Vora
Updated on 16-Feb-2023 15:33:06

8K+ Views

Sometimes, we require to use the checkbox inside the select option. We can allow users to select multiple options by introducing the checkboxes with the select option. However, if we use the multiple attributes with the tag, it allows us to select them by pressing the ‘ctrl + left click’, but it is a bad UX. So, we can introduce the checkbox inside the menu to improve the user experience. Here, we will use JQuery and JavaScript to manage the values of the checked checkboxes in the menu. Create a custom select menu The element of ... Read More

Use Await Outside of an Async Function in JavaScript

Shubham Vora
Updated on 16-Feb-2023 15:31:59

2K+ Views

In JavaScript, the async-await keyword is used to make the function asynchronous. If we make any function asynchronous, it works like multithreading and executes the code parallelly, which helps us to improve the application performance. Here, we will learn to use the await keyword outside the asynchronous function. Invoke the function immediately We will use the expression in this approach to invoke the function immediately. We can use the await keyword with the promises or any other function inside the function. Syntax Users can follow the syntax below to use the function expression to invoke the function immediately. (async () ... Read More

Calculate Minutes Between Two Dates in JavaScript

AmitDiwan
Updated on 16-Feb-2023 15:31:26

12K+ Views

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(). JavaScript will use the browser's time zone and display a date as a full text string. Example 1 In this example, we use a function to find the time difference. function minutesDiff(dateTimeValue2, dateTimeValue1) { var differenceValue =(dateTimeValue2.getTime() - dateTimeValue1.getTime()) / 1000; differenceValue /= 60; return Math.abs(Math.round(differenceValue)); } dateTimeValue1 = new Date(2020, 12, 12); console.log("The first date time value is defined ... Read More

Add Element to JSON Object Using JavaScript

AmitDiwan
Updated on 16-Feb-2023 15:29:18

29K+ Views

In this article, you will understand how to add an element to a JSON object using JavaScript. JSON object literals are keys and values are separated by a colon surrounded by curly braces {}. Example 1 In this example, we add an element to a json object using bracket notation, var jsonObject = { members: { host: "hostName", viewers: { userName1: "userData1", ... Read More

Check an Object Against a Property Using Array Includes

Shubham Vora
Updated on 16-Feb-2023 15:27:55

4K+ Views

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() method 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 Users can follow the syntax below to use the ... Read More

Swap Two Variables in JavaScript

Shubham Vora
Updated on 16-Feb-2023 15:26:54

2K+ Views

We will learn to swap two variable values in JavaScript using various approaches. Let’s understand via example what swapping means. For example, we have two variables called variable1 and variable2. When we assign the values of variable2 to variable1 and the value of variable1 to variable2, we can say that we have swapped the values of variable1 and variable2. Use the temporary variable We can create a temporary variable, which means any variable to store the value of the first variable temporarily. After that, we can assign the value of the second variable to the first variable. Next, we can ... Read More

Access Object Properties from Async Function Result in JavaScript

AmitDiwan
Updated on 16-Feb-2023 15:24:54

937 Views

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. Example 1 In this example, let’s understand how to access objects property using dot notation console.log("A function is created that returns promise object") const promiseFunction = (input) => { return new Promise((resolve, reject) => { return resolve({ ... Read More

Sort Option Elements Alphabetically Using jQuery

Shubham Vora
Updated on 16-Feb-2023 15:24:17

7K+ Views

Sometimes, we require sorting the options of the dropdown menu in alphabetical order. For example, you are selling computers on your website, and you want to allow users to select a computer based on the model. If your website contains hundreds of models of different brands, it will be hard for users to find a computer with a particular brand if it is not sorted. However, you can provide the search functionality but if it’s not there, then sorting all the option elements in alphabetical order is better. Here, we will learn various approaches to sort all options of the ... Read More

Calculate Days Left Until Next Christmas Using JavaScript

AmitDiwan
Updated on 16-Feb-2023 15:22:58

855 Views

In this article, you will understand how to calculate days left until next Christmas using JavaScript. The Date object works with dates and times. Date objects are created with new Date(). JavaScript will use the browser's time zone and display a date as a full text string. Example 1 In this example, we compute the time difference without functions. let todayDate = new Date(); console.log("Today's date is defined as: ", todayDate) let christmasYear = todayDate.getFullYear(); if (todayDate.getMonth() == 11 && todayDate.getDate() > 25) { christmasYear = christmasYear + 1; } let christmasDate = new Date(christmasYear, 11, ... Read More

Advertisements