Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
jaxim
Visitor

toString function for Array

How do you convert an array to a string?

I've tried to look thru the documentation for answers but it seems a bit lacking

https://sdkdocs.roku.com/display/sdkdoc/roArray 
0 Kudos
5 REPLIES 5
RokuKC
Roku Employee
Roku Employee

Re: toString function for Array

"jaxim" wrote:
How do you convert an array to a string?

I've tried to look thru the documentation for answers but it seems a bit lacking

https://sdkdocs.roku.com/display/sdkdoc/roArray 

What is it you want to do with the resulting string?
If the array consists of plain value types (string, integer, etc., or nested associative array or array of those), FormatJSON(array) might work for you.
0 Kudos
jaxim
Visitor

Re: toString function for Array

Using JavaScript as an example, I would like to convert the values contained in an array to a comma delineated string like the following:
var monthNames = ['Jan', 'Feb', 'Mar', 'Apr'];
var myVar = monthNames.toString(); // assigns 'Jan,Feb,Mar,Apr' to myVar.


Source: https://developer.mozilla.org/en-US/doc ... y/toString
0 Kudos
RokuKC
Roku Employee
Roku Employee

Re: toString function for Array

"jaxim" wrote:
Using JavaScript as an example, I would like to convert the values contained in an array to a comma delineated string like the following:
var monthNames = ['Jan', 'Feb', 'Mar', 'Apr'];
var myVar = monthNames.toString(); // assigns 'Jan,Feb,Mar,Apr' to myVar.



There's no intrinsic support for that in the current firmware.
You could write your own utility function for it.

myVar = "" : for each ms in monthNames : myVar  += "," + ms : end for : myVar = myVar.Mid(1)
print myVar
0 Kudos
jaxim
Visitor

Re: toString function for Array

thanks, RokuKC! 
0 Kudos
EnTerr
Roku Guru

Re: toString function for Array

"jaxim" wrote:
Using JavaScript as an example, I would like to convert the values contained in an array to a comma delineated string

There is proposal to add exactly that - go and add your vote and voice @ https://forums.roku.com/viewtopic.php?f=34&t=96430
0 Kudos