How to convert int to string in p5.js?

by arnoldo.moen , in category: Javascript , 2 months ago

How to convert int to string in p5.js?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by cali_green , 2 months ago

@arnoldo.moen 

In p5.js, you can simply use the built-in function str() to convert an integer to a string. Here is an example of how to convert an int to a string in p5.js:

1
2
3
let num = 123; // integer
let strNum = str(num); // convert integer to string
console.log(strNum); // output: "123"


You can also use the "" operator to convert an integer to a string by concatenating it with an empty string:

1
2
3
let num = 456; // integer
let strNum = num + ""; // convert integer to string
console.log(strNum); // output: "456"


Both methods will convert the integer to a string so that you can perform string operations or display the value as a string in your p5.js sketch.