Navigate back to the homepage

How to convert any to string in typescript?

April 14th, 2022 · 1 min read
keep affilitate

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 number
3let 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.


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

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.

melio affilitate

Looking For React Native Tutorial?

we are trying to create the best Tutorial for react native developers.

When you want a daily updates about React Native Tutorial or infinitbility update subscribe to our newsletter.

Read React Native Tutorial

Request New Tutorial or Article on mail [email protected]

Guide book

Guidebook: The Javascript Monorepo Photoshop Guide



More articles from Infinitbility

How to convert object to json string in typescript?

TypeScript, convert object to json string example.

April 14th, 2022 · 1 min read

How to convert string to json in typescript?

TypeScript, convert string to json example.

April 14th, 2022 · 1 min read
© 2020–2022 Infinitbility
Link to $ to $ to $ to $ to $ to $mailto:[email protected]