Slice String JavaScript de l'index à l'espace

const data ="Hello my name is Hastings"
data = data.slice(0, data.indexOf(" ")); 
console.log(data)
//Output = "Hello"
Hastings Keith