Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

Add Space After (Comma) In Array Push.

arobertson
Tera Guru

Hi,

The below code takes a list collector full of names and prints them out as follows: user1,user2,user3. I would like to add a space after each comma like so. user1, user2, user3.

var answer1 = [];

var list1 = current.variables.admin_group_owners.toString();

var listArr1 = list1.split(',');

for (var i=0;i<listArr1.length;++i) {

  var user1 = new GlideRecord('sys_user');

  user1.addQuery('sys_id',listArr1[i]);

  user1.query();

  if(user1.next()){

  answer1.push(user1.email.toString());

  }

}

task.description = 'Group Members: ' + answer1;

Regards.

1 ACCEPTED SOLUTION

Tanaji Patil
Tera Guru

Hi Alex,



Try writing below lines of code at the end. This should give you required result.



var answer1_final = answer1.join(', ');         //there is space after comma


task.description = 'Group Members: ' + answer1_final;



Thanks,


Tanaji


View solution in original post

2 REPLIES 2

Tanaji Patil
Tera Guru

Hi Alex,



Try writing below lines of code at the end. This should give you required result.



var answer1_final = answer1.join(', ');         //there is space after comma


task.description = 'Group Members: ' + answer1_final;



Thanks,


Tanaji


Perfect,



I did look at join but was putting it in the wrong place.