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.
1// data should be any thing like array, object, and number.2// here we are going with array of number3let data: any = [1, 2, 3, 4];4console.log(typeof data)5data = data.toString();6console.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

All the best 👍.
Follow me on Twitter
Join our email list and get notified about new content
No worries, I respect your privacy and I will never abuse your email.
Every week, on Tuesday, you will receive a list of free tutorials I made during the week (I write one every day) and news on other training products I create.