Search code examples
javascriptarraysstringnetsuiteopenair

Javascript Add Item in Array to string


I am trying to make a multiline string from taking an array of user ids and matching them to the username and then printing the string.

This is what I have so far and am wondering what the proper way to do this would be:

var names;
for(var i in array) {
    var obj = new NSOA.record.oaUser(i);
    var username = obj.name;
    names = names + username;
}

Ideally names would be a string that looks like:

"Smith, Bob, Doe, Jane, Miller, Larry"

Any help you can give would be very much appreciated!


Solution

  • If you're printing to HTML insert a <br> after each array element in the string:

    var names = '';
    for(var i in array) {
        var obj = new NSOA.record.oaUser(i);
        var username = obj.name;
        names = names + username + '<br>';
    }