Found 26504 Articles for Server Side Programming

How to replace substring in string in TypeScript?

Shubham Vora
Updated on 03-Jan-2023 12:18:52

1K+ Views

Sometimes, we need to replace a substring with a new string or any particular character while working with TypeScript. The simple way to replace the substring or part of the string is to use the replace() method. Here, we will create a custom algorithm to replace the string for the interview purpose of the beginners. However, we will also see the replace() method at last in this tutorial. Create the Custom Algorithm to Replace the Substring We will use the for loop to iterate through the main string in this part. We will use the substr() method of the string ... Read More

How to join multiple arrays in TypeScript?

Shubham Vora
Updated on 03-Jan-2023 12:33:23

4K+ Views

The array stores the elements of the different data types in TypeScript. It is a collection of elements we can use it to store and access data whenever required. While working with multiple arrays, we need to combine two or more arrays. There are several ways to combine multiple arrays in TypeScript, and we will look through all ways in this TypeScript tutorial. Also, we will discuss when we should use which way is the best at last. Uing The For Loop to Join The Two Arrays We can follow the traditional way of using the for-of loop to join ... Read More

What is Type Assertion in TypeScript?

Shubham Vora
Updated on 03-Jan-2023 12:00:27

5K+ Views

Type assertion is a mechanism in TypeScript that informs the compiler of the variable type. We can override the type using a type assertion if TypeScript finds that the assignment is wrong. We must be certain that we are correct since the assignment is always legitimate when we employ a type assertion. If not, our program might not operate properly. Declaratively informing the compiler that we intend to regard the item as a distinct type is known as type assertion. Using this, we can regard any as a number or a number as a string. When moving code from JavaScript ... Read More

How to use typeof operator in TypeScript?

Shubham Vora
Updated on 03-Jan-2023 11:56:15

1K+ Views

In TypeScript, the typeof is one of the most helpful operators and keywords to check the types of variables or identifiers. However, TypeScript is a type-strict language. So, we need to define the type of the variable or object while defining the identifier itself. Still, sometimes we need to check the type of the variable. For example, we are taking the data from the user via forms and handling it via TypeScript. Then we have to validate the data and perform some database operations. Also, the identifier can have multiple types in TypeScript. So, using the typeof operator, we can ... Read More

How to specify optional properties in TypeScript?

Shubham Vora
Updated on 03-Jan-2023 11:53:53

1K+ Views

We will learn to specify the option properties in TypeScript. The true meaning of the optional property is that properties can be undefined or null, and we can initialize them whenever required. In real-time development, the importance of optional properties is very much. For example, we are fetching the data from the API and performing some operations on the data. If you try to use the data without getting it due to the database server being down or if there is any other problem, it will raise an error. In such case, we can make the data property optional and ... Read More

How to get substring in TypeScript?

Shubham Vora
Updated on 03-Jan-2023 11:51:17

725 Views

The string contains various characters, and the substring is the part of the string. We can get the substring from the string two ways. The first is using the starting and ending position of the substring, and the second is using the starting position and length of the substring. We will learn both ways to get the substring from the string in TypeScript in this tutorial. Get The Substring Using The Start Position and End Position In TypeScript, indexing of string starts from zero. So, if we have a zero-based starting and ending position of the substring, we can get ... Read More

How to find the natural logarithm of a number in TypeScript?

Shubham Vora
Updated on 03-Jan-2023 11:48:34

630 Views

The natural logarithm is the logarithm of any numeric value to the base e. Here e is Euler's constant, and the value of Euler’s constant is approximately 2.718. In TypeScript, we can use the built-in library methods to find the natural logarithm of any numeric value greater than or equal to zero. Using the Math.log() Method Math is a library of TypeScript which contains all the methods to perform mathematical operations. Inside the Math object, all methods are static. So, we can directly access all methods by taking Math (object name) as a reference. The math method also contains the ... Read More

How to create an array of objects in TypeScript?

Shubham Vora
Updated on 03-Jan-2023 11:46:04

16K+ Views

In TypeScript, the array contains the data or different values and can also contain an object. The object contains the properties and methods in TypeScript. We can access the object properties and invoke the object method by taking the object as a reference. In this tutorial, we will learn to create an array of multiple objects in TypeScript. We will also learn to perform some operations, such as sorting on the array of objects. Syntax Here, we have given the syntax to follow to create the array of objects. let obj_array: Array = [{object properties}] In the above syntax, ... Read More

Precision String Format Specifier In Swift

Nitin Aggarwal
Updated on 03-Jan-2023 10:32:41

2K+ Views

It is sometimes necessary to format strings in a custom format in order to use them in an application. For example, you can format product prices, decimal-point numbers, etc. In Swift, you can use precision specifiers to specify the number of decimal places or the number of characters to be displayed in a string. Example 1 To specify the number of decimal places for a floating-point number, you can use the %.nf format specifier, where n is the number of decimal places., import Foundation let productPrice = 300.3456789 let formattedPrice = String(format: "%.2f", productPrice) print("The formatted price is: ", formattedPrice) ... Read More

How to use a Background Thread in Swift?

Nitin Aggarwal
Updated on 03-Jan-2023 10:26:51

8K+ Views

In this article, you will learn how you can perform a task in the background using a background thread in the Swift language. Swift provides us with several ways to perform background tasks. One popular option of theirs is GCD (generally called Grand Central Dispatch), which is a low-level API for managing concurrently in the Swift language. The GCD provides us with a global queue for creating background threads. You can invoke the DispatchQueue.global() method to get an instance of a global dispatch queue. Using the same instance, you can use the async() method to execute a block of code ... Read More

Advertisements