how to get length of numbers in typescript?

Get the length of numbers in typescript To get the length of numbers in typescript, you can use the toString() method with the length property it will return the length of numbers. // ✅ Get the length of numbers in typescript let num: number = 493054; num.toString().length; // 👉️ 6 Today, I’m going to show you How do I get the length of numbers in typescript, as above mentioned here, I’m going to use thetoString() method with the length property to get the length of numbers;...

July 28, 2022 · 1 min · Infinitbility

how to get length of object in typescript?

Get the length of the object in typescript To get the length of the object in typescript, you can use the Object.keys() method with the length property it will return the length of the object. // ✅ Get the length of the object in typescript let num: number = 493054; Object.keys({id: 1, name: "infinitbility.com"}).length; // 👉️ 2 Today, I’m going to show you How do I get the length of the object in typescript, as above mentioned here, I’m going to use theObject....

July 28, 2022 · 1 min · Infinitbility

how to add number to string in typescript?

Add a number to a string in typescript To add the number to a string in typescript, you can use the + addition operator or ${} template literal to add a number in a string both can add the number to a string. // ✅ Using `+` addition operator 5 + "0" 👉️ "50" // ✅ Using `${}` template literal `${5}0` 👉️ "50" Today, I’m going to show you How do I add a number to a string in typescript, as above mentioned here, I’m going to use the + addition operator or ${} template literal to add the number to a string....

July 27, 2022 · 2 min · Infinitbility

how to export constants in typescript?

Export constants in typescript To export constants in typescript, use the export keyword it will export your constants, variables, or functions. To use export constants, variables, or functions in typescript, use the import keyword. using the import keyword you can easily use exported module. Today, I’m going to show you How do i export constants in typescript, as mentioned above, I’m going to use the use export statement to export constants and use them in another file....

July 24, 2022 · 1 min · Infinitbility

how to extract numbers from the string in typescript?

Extract number from string in typescript To extract a number from a string in typescript, use the match() method with the /\d+/g regex it will find all numbers from the string and return as an array of numbers. const REGEX = /\d+/g; let sampleString: string = "#div-name-1234-characteristic:561613213213"; let arrOfNumber: Array<number> = sampleString.match(REGEX); // 👇️ [ '1234', '561613213213' ] console.log(arrOfNumber) Today, I’m going to show you How to i extract a number from a string in typescript, as mentioned above, I’m going to use the use match() and join() method with /\d+/g regex to extract numbers from string and convert in digits....

July 24, 2022 · 2 min · Infinitbility

how to check empty string in typescript?

check an empty string in typescript To check an empty string in typescript, use the if..else statement just pass and put your string variable in an if condition if it’s empty it will go to the else statement. Today, I’m going to show you How do i check an empty string in typescript, as mentioned above, I’m going to use the use if..else statement to check the typescript empty string....

July 20, 2022 · 1 min · Infinitbility

how to stringify json object in typescript?

Stringify JSON object in typescript To stringify json object in typescript, use JSON.stringify() it will convert your json object to json string. The JSON.stringify() method converts a JavaScript object or value to a JSON string, optionally replacing values if a replacer function is specified or optionally including only the specified properties if a replacer array is specified. interface domain { name: string, domain: string, } const arr: Array<domain> = [ { name: "infinitbility", domain: "infinitbility....

July 20, 2022 · 1 min · Infinitbility

how to convert array to string in typescript?

Convert array to string in typescript To convert array to string in typescript, use the join() method it will convert the array to a comma (,) separated string. The join() method creates and returns a new string by concatenating all of the elements in an array (or an array-like object), separated by commas or a specified separator string. If the array has only one item, then that item will be returned without using the separator....

July 19, 2022 · 2 min · Infinitbility

how to remove space from string in typescript?

Remove all space from the string in typescript To remove all white space from the string in typescript, use the replace() method with the /\s/g regex it will remove all whitespace from the string. const str: string = ' first second third '; // ✅ Remove all Whitespace const withoutAnyWhitespace: string = str.replace(/\s/g, ''); console.log(withoutAnyWhitespace); // 👉️ "firstsecondthird" Remove whitespace from the beginning and end of the string in typescript To remove space from the start and end of the string in typescript, use the trim() method it will remove space from both sides and return a new string....

July 18, 2022 · 2 min · Infinitbility

how to add double quotes in string in typescript?

Add double quotes in string in typescript To add double quotes in the string in typescript, use double quotes both side with the + operator it will concatenate the string and return a new string with double quotes like below example. let str: string = "infinitbility"; // add double quotes str = '"' + str + '"'; console.log(str) // 👉️ '"infinitbility"' Add double quotes at the beginning of string in typescript To add double quotes at the beginning of string in typescript, use double quotes at starting of the string with the + operator it will concatenate the string and return a new string with double quotes like below example....

July 17, 2022 · 2 min · Infinitbility

how to add new line in string in typescript?

Add new line in string in typescript To add a new line in string in typescript, use new line \n with the + operator it will concatenate the string and return a new string with a new line separator. let str: string = ""; // add new line str = "Hi Friends" + "\n"; str = str + "Welcome to Infinitbility"; console.log(str) // Output // 'Hi Friends // Welcome to Infinitbility' put the "\n" where you want to break the line and concatenate another string....

July 16, 2022 · 1 min · Infinitbility

how to add space in string in typescript?

Add space beginning of the string in typescript To add space beginning of the string in typescript, use blank space with the + operator it will concatenate the string and return a new string with space. let str: string = "infinitbility"; // add blank space str = " " + str; console.log(str) // 👉️ " infinitbility" To show space at the beginning of the string you should put a blank space string before the + operator, like in the above example....

July 16, 2022 · 2 min · Infinitbility

How to check both undefined and null in typescript?

Hi Friends 👋, Welcome to Infinitbility ❤️! Today, we are going to learn how we can check both undefined and null in typescript, here we will use the check falsy value concept to check both undefined and null. To handle, false, '', undefined, null, and other false value we can easily manage in single default condition in typescript. Here, we have to just check variables in if cases. Well, we will take an example of undefined, and null....

May 10, 2022 · 1 min · Infinitbility

How to get last element of array in typescript?

Hi Friends 👋, Welcome to Infinitbility ❤️! Today, we are going to learn How to get the last element of the array in typescript?, here we will use basic array length syntax to find the last element of the array. So, when we want to know how many elements are in an array we will use array.length and it will return a number of elements in an array. Well, what we can do here, is we will use array....

May 9, 2022 · 1 min · Infinitbility

How to get random number in typescript?

Hi Friends 👋, Welcome to Infinitbility ❤️! Today, we are going to learn How to get a random number in typescript?, here we will use Math.ceil(), Math.floor(), and Math.random() methods to generate random as per our requirement. Before going to code, let first understand what is those methods. Math.ceil() The Math.ceil() function always rounds a number up to the next largest integer. Math.floor() The Math.floor() function returns the largest integer less than or equal to a given number....

May 8, 2022 · 1 min · Infinitbility

How to get value from object by key in typescript?

Hi Friends 👋, Welcome to Infinitbility ❤️! Today, we will learn how to get value from an object by key in typescript, here we will use some basic syntax to get value from an object. Here, we will see Access object value using the dot method Access object value using bracket method ( we can also use it for dynamic value access ) In the code below, we create a sample object variable to store sample dog data....

May 7, 2022 · 1 min · Infinitbility

How to convert date to milliseconds in typescript?

Hi Friends 👋, Welcome to Infinitbility ❤️! Today, we are going to learn How to convert date to milliseconds in typescript?, here we will use the date built-in method getTime() to get a date in milliseconds. Intro to getTime() The getTime() method returns the number of milliseconds since the ECMAScript epoch. A number representing the milliseconds elapsed between 1 January 1970 00:00:00 UTC and the given date. Code summary Here, we will see what we are going to do:...

May 2, 2022 · 1 min · Infinitbility

How to convert date to iso format in typescript?

Hi Friends 👋, Welcome to Infinitbility ❤️! This tutorial will help you to convert date to iso format in typescript, here we will use the toISOString() method to convert date to iso format. what is toISOString()? The toISOString() method returns a string in simplified extended ISO format (ISO 8601), which is always 24 or 27 characters long (YYYY-MM-DDTHH:mm:ss.sssZ or ±YYYYYY-MM-DDTHH:mm:ss.sssZ, respectively). The timezone is always zero UTC offset, as denoted by the suffix “Z”....

May 1, 2022 · 1 min · Infinitbility

How to convert date to timestamp in typescript?

Hi Friends 👋, Welcome to Infinitbility ❤️! Today, we are going to learn How to convert a date to the timestamp in typescript?, here we will use the date built-in method Date.parse() method to convert the date to timestamp format. So, let’s see what is Date.parse() method is? The Date.parse() method parses a string representation of a date and returns the number of milliseconds since January 1, 1970, 00:00:00 UTC or NaN if the string is unrecognized or, in some cases, contains illegal date values (e....

April 29, 2022 · 1 min · Infinitbility

How to convert date to mm/dd/yyyy in typescript?

Hi Friends 👋, Welcome to Infinitbility ❤️! Today, we are going to learn How to convert date to mm/dd/yyyy in typescript?, here we will use custom method formatDate() method to convert date to mm/dd/yyyy format. So, first we have to create a function which get date as a parameter and return formated like we want… Here, we want format date as month/date/year like. let’s dive in code… const formatDate = (date: Date) => { function pad(s) { return (s < 10) ?...

April 27, 2022 · 1 min · Infinitbility