const str = ' apple banana kiwi '; const result = str.split(' ').filter(element => element); console.log(result); //['apple', 'banana' , 'kiwi']