Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

get first word of string js

let myStr = "Hello World"
let firstWord = myStr.split(" ")[0]
Comment

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
Comment

get the first word of a string javascript

let sentence = "The big brown fox"
let word = sentence.split(" ")[0]

console.log(word) // The
Comment

PREVIOUS NEXT
Code Example
Javascript :: parseint() js 
Javascript :: Convert a string to an integer in jQuery 
Javascript :: return the next higher prime number javascript 
Javascript :: multiple transform properties javascript 
Javascript :: loop array and check if value matches in js 
Javascript :: create infinite loop using for loop in javascript 
Javascript :: repeat react component n times 
Javascript :: the submitted data was not a file. check the encoding type on the form django react 
Javascript :: replace backward slash in javascript 
Javascript :: javascript last element of an array 
Javascript :: javascript game loop 
Javascript :: get buffer from file javascript 
Javascript :: how to test usestate in jest 
Javascript :: react native create view dynamically 
Javascript :: how to hide url parameters in address bar using javascript 
Javascript :: install react js 
Javascript :: how to disable react in jsx scope eslint 
Javascript :: encode in javascript 
Javascript :: splidejs autoscroll 
Javascript :: jwt token expire times 
Javascript :: radio button in react 
Javascript :: keypress javascript 
Javascript :: express get client ip 
Javascript :: disable submit button until checkbox is checked javascript 
Javascript :: jquery selector checked 
Javascript :: jquery bind click 
Javascript :: join text in js 
Javascript :: video preview javascript 
Javascript :: dom click is not a function 
Javascript :: javascript for loop on object 
ADD CONTENT
Topic
Content
Source link
Name
5+5 =