Return the first word in a string

I would like to use the JavaScript Transform to create a new column that contains the first word of an existing column.

What is the JavaScript to do so?

I didn’t see an example in the JavaScript Help documentation.

Perhaps the Extract Transform could contain some basic selectable arguments such as return First Word, First # words, Last word, Last # words.

@DanFeliciano

To turn this:

f1

Into:

f2

It is probably simplest to use Replace with a regex.

f3

NB/ You can also use regex inside a Javascript transform.

Why not use the Split transform with a delimiter of space with min and max of 1? I know you asked for JavaScript but if I understand the problem correctly this would be a
very simple solution.

2 Likes

Good call @Vann . That is simpler than a regex.

That worked brilliantly.

Excellent.

1 Like