Fixing potential JS error when text is an array with undefined as the first element