How to console log a word in a string?

I'm wondering how to console.log a word from a string based on the index.

let word = "Hello world";
console.log(word[0]) //log from index 0 to 4

How to log from index 0 to 4, because now i only know how to log a single letter.


Solution 1:

Like this:

let word = "Hello world";
let wordArray = word.split(" ");
console.log(wordArray[0])

Solution 2:

Split your string by your separator in your case space:

console.log(word.split(" ")[0]);