You can use the split()
and map()
functions to achieve this result. First, you need to split the string into an array of lines using the split()
function. Then, you can map()
through this array and get the first word of each line using the split()
function again, this time splitting each line on its whitespace characters. The first word will then be the first element in the resulting array. Here's the code:
index.tsx184 chars6 lines
gistlibby LogSnag