Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

JavaScript - The first word of a string

const str = "What day of the week is it?";

// 1) the match() method:
str.match(/^w+s/)[0];// => What

// 2) the split() method:
str.split(' ')[0];  // => What

// 3) the slice() method:
str.slice(0, str.indexOf(' ')); // => What
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #JavaScript #The #word #string
ADD COMMENT
Topic
Name
5+4 =