Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Search instead for 
Did you mean: 
jaxim
Level 7

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
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
Level 7

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
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
Level 7

Re: toString function for Array

thanks, RokuKC! 
0 Kudos
EnTerr
Level 8

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