Hi Friends đź‘‹,

Welcome to Infinitbility ❤️!

This tutorial will help you to convert any type of data to a string in typescript, here we will use the built-in method .toString() method to convert data any type to a string.

we will first create any type variable with sample array data and then we will check their data type. after that we will use the .toString() method to convert it into a string.

Then we will recheck the datatype of the data variable.

Let’s write code.

// data should be any thing like array, object, and number.
// here we are going with array of number
let data: any = [1, 2, 3, 4];
console.log(typeof data)
data = data.toString();
console.log(typeof data)

when I run the above code, in the first console I get object and in the second string, check the output.

Output

TypeScript, convert any to string example
TypeScript, convert any to string example

All the best đź‘Ť.