Forum Discussion

  • RokuKC's avatar
    RokuKC
    Roku Employee
    "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.
  • 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
  • RokuKC's avatar
    RokuKC
    Roku Employee
    "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