How to remove undefined from the start of the array in transform map script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā10-19-2022 10:10 PM - edited ā10-20-2022 02:53 AM
Hi I have a list type field delegates in my user table which iam updating via transform map
how to remove the empty values
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā10-19-2022 10:31 PM
Hello @test1231998 ,
To me it looks like undefined is part of the first sys_id listed. Otherwise there would be a comma after the undefined but there isn't. One quick way to find that out is to check the length of the array. If undefined is by itself it will still count as an item. If it isn't part of that first sys_id then use the .filter method before the join like below. The filter method will only return a truthy value and return an array with those values.
...
return delegates.filter(function(delegate){ return delagate; }).join(",");
...
If the undefined ends up being a part of the first variable then use the .map method with returning the item with a replace method to remove 'undefined'. The map will return that array and then you can use the join method. Like the following:
...
return delegates.map(function(delegate){return delegate.replace("undefined","")}).join(",");
...