Action Help: Backspace / Delete with JS

I am running a loop that adds a number of lines to a draft using:

d.content = d.content + addedtext + "\n";

This works fine, but adds a return for the last item in the loop. Struggling to figure out how to essentially hit the backspace key and remove the last “\n”. Any elegant ways to do this?

Does join() work for you?

So learning as I go…

var texttojoin = ["input-one", "input-two", "input-three"];
var joining = texttojoin.join("\n");
d.content = d.content + joining;
d.update();

And it worked! So much easier to connect the array - appreciate the help.

I learnt this one from a @RosemaryOrchard video on YouTube about 2 hours ago, as it happens. :smiley:

(I knew about split() but her Drafts example reminded me about join().)

1 Like

The Javascript String object trim method is also handy to know about. join makes more sense here, but if you have input you may need to strip of whitespace to make sure you don’t end up with extra line feeds, it’s useful. It removes any whitespace at the beginning and end.

1 Like

Indeed - was looking at trim first - trying to put that in place elsewhere. Adapting the add to Drafts List action to prepend or append, but running into issues with the ## Title portion of the note. Probably not right for this thread - but this is where a seperate “title” portion of a note would be nice to have…