1

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!

Braj
  • 46,415
  • 5
  • 60
  • 76

2 Answers2

0

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>';
}
TomSlick
  • 717
  • 5
  • 21
0

Push all the name in an array then finally Join it by any separator.

For example:

var arr = [];

arr.push('Smith');
arr.push('Bob');
arr.push('Doe');
arr.push('Jane');
arr.push('Miller');
arr.push('Larry');

document.write(arr.join(', '));
Braj
  • 46,415
  • 5
  • 60
  • 76