Web Development Articles

Page 294 of 801

How to create asynchronous function in TypeScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 7K+ Views

Asynchronous programming allows us to perform multiple tasks without blocking code execution. In TypeScript, we use the async/await keywords to create asynchronous functions that handle promises elegantly. Before diving in, let's understand why asynchronous programming is essential. When fetching data from APIs or performing I/O operations, these tasks take time to complete. In single-threaded languages like TypeScript and JavaScript, synchronous code would block execution until the operation finishes, leading to poor performance. Asynchronous functions solve this by allowing other code to execute while waiting for time-consuming operations to complete. The await keyword pauses execution only within the async ...

Read More

How to solve too many try catch in Typescript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 1K+ Views

We can use the try-catch statements to handle errors in TypeScript. Sometimes, we require adding more than one try-catch block in the code to handle multiple errors. When we add multiple try-catch statements in the code, the code becomes unreadable, and it becomes a headache for developers to refactor. In this tutorial, we will learn to convert too many try-catch blocks into a single try-catch block which can manage multiple errors. Syntax Users can follow the syntax below to use the single try-catch block in TypeScript. try { throw new Error("error_message"); ...

Read More

How to Develop Generic Classes

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 277 Views

Generic classes in TypeScript allow you to create flexible, reusable classes that can work with multiple data types. They use type parameters enclosed in angle brackets () to represent the type of data the class will handle, making your code more versatile and type-safe. A generic class uses type parameters (commonly denoted as "T") as placeholders for actual types. When you instantiate the class, you specify the concrete type, and the class properties and methods adapt accordingly. This approach eliminates code duplication while maintaining type safety. Syntax The basic syntax for creating a generic class in TypeScript ...

Read More

How to Enforce the type of the indexed members of a Typescript object

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 677 Views

TypeScript is a strongly typed, object-oriented programming language built on JavaScript. One of its powerful features is the ability to enforce types of an object's indexed members using index signatures. This allows you to define the shape of objects with dynamic properties while maintaining type safety. An index signature specifies the types for both keys and values in an object. It's particularly useful when you need objects with unknown property names but known value types. Syntax interface ObjectType { [key: string]: ValueType; } // Or inline let objectName: { [key: string]: ...

Read More

How to convert JavaScript datetime to MySQL datetime?

Saurabh Jaiswal
Saurabh Jaiswal
Updated on 15-Mar-2026 2K+ Views

Date time manipulation in JavaScript is important while dealing with databases. JavaScript Date and time are different from the MySQL date and time. JavaScript provides multiple ways to represent Date and time none of these formats are the same as MySQL's date and time format. In this article, we will discuss some approaches to converting JS date and time into MySQL date and time format. First of all, we will understand the difference between Javascript and MySQL date and time formats. Here is an example − Javascript − ISO 8601 Date Format: YYYY-MM-DDTHH:mm:ss.sssZ MySQL ...

Read More

How to convert Object's array to an array using JavaScript?

Saurabh Jaiswal
Saurabh Jaiswal
Updated on 15-Mar-2026 9K+ Views

Converting an array of objects to a flat array is a common task in JavaScript. There are several approaches to extract all values from objects and create a single array containing those values. Let's understand the problem with an example: Given Array of Objects: let carObj = [ { name: "John", car: "Ford" }, { name: "Mark", car: "BMW" }, { name: "Ben", car: "Toyota" } ] Expected Output: ["John", "Ford", "Mark", "BMW", "Ben", "Toyota"] There are multiple ways to achieve this conversion: ...

Read More

How to convert list of elements in an array using jQuery?

Saurabh Jaiswal
Saurabh Jaiswal
Updated on 15-Mar-2026 5K+ Views

We can use jQuery.makeArray() method or jQuery.each() method to convert a list of elements into an array using jQuery. The makeArray() method is the most convenient way to perform this task. This method is used to convert an object into a native array. Using jQuery makeArray() Method The $.makeArray() method in jQuery converts an array-like object into a JavaScript array. It takes a single argument and converts it to an array. Syntax $.makeArray(obj) Here obj is an object that we want to convert to an array. Example In this example we ...

Read More

How to convert JSON results into a date using JavaScript?

Saurabh Jaiswal
Saurabh Jaiswal
Updated on 15-Mar-2026 8K+ Views

JSON is a powerful data format to exchange data from server to client and vice versa. Many times JSON data is received in a String format and we need to convert it to a usable JSON object. In this process, it's an important requirement to convert string data into Date format. In this article, we will learn how to convert JSON results into a Date string using JavaScript. The JSON objects contain the date like this − { name: "John", time: '/Date(1559072200000)/' } And the result will be − ...

Read More

How to convert Map keys to an array in JavaScript?

Saurabh Jaiswal
Saurabh Jaiswal
Updated on 15-Mar-2026 13K+ Views

In JavaScript, you can convert a Map's keys to an array using several methods. The most common approaches are using Array.from(), the spread operator, or a for...of loop with Map.keys(). Given a JavaScript Map, the task is to extract all keys and create an array from them. Here's an example: Given Map: Map { 1 => "India", 2 => "Russia", 3 => "USA", 4 => "Japan", 5 => "UK" } Resulting Array: [1, 2, 3, 4, 5] There are multiple ways to achieve this conversion: Using Array.from() and Map.keys() method ...

Read More

How to convert NaN to 0 using JavaScript?

Saurabh Jaiswal
Saurabh Jaiswal
Updated on 15-Mar-2026 4K+ Views

We can use the logical OR operator, double bitwise NOT operator, strict equality operator, or the isNaN() function to convert NaN to 0 using JavaScript. NaN in JavaScript means Not a Number, whose type is Number but actually, it is not a number. In this article, we will learn different approaches to convert NaN to 0. Using the Logical OR (||) Operator Using the Double Tilde (~~) Operator Using the Strict Equality (===) Operator Using the isNaN() function Using the Logical OR (||) Operator ...

Read More
Showing 2931–2940 of 8,010 articles
« Prev 1 292 293 294 295 296 801 Next »
Advertisements