split() - don't show 'undefined' text for blank data cell
I'm an animator working with JS in AE expressions and I have to make dynamic charts with CSV data controlling points and values. That's all going fine, but what I'm stuck on is that some name value are two words, some are single, and I need to break up the double words onto two lines. When I do it the way I found, the single words display as the word on the first line, and the word 'undefined' on the second line. Obviously because there isn't a second value.
Is there a better way to script the line break so there isn't an undefined value? It needs to be flexible for one or two words in either cell.
Here's the code I have so far :
(I've simplified the for loop cos it linked to other layer names)
i=**forLoop;
nameText = footage("Spreadsheet.csv").dataValue([0,i]);
nameText.split(" ")[0] + ['\n'] + nameText.split(" ")[1]