Basic JavaScript - Find the Length of a String

You can find the length of a String value by writing .length after the string variable or string literal.

console.log("Alan Peter".length);

The value 10 would be displayed in the console. Note that the space character between “Alan” and “Peter” is also counted.

For example, if we created a variable const firstName = "Ada", we could find out how long the string Ada is by using the firstName.length property.

Use the .length property to set lastNameLength to the number of characters in lastName.

Based on my understanding of the question, it seems you are looking for something like this.

The split() method splits a string into an array of substrings.

The split() method returns the new array.

The split() method does not change the original string.

console.log(“Alan Peter”.split(" ")[1] .length)

// output : 5

1 Like

Welcome to the community @2281015 !

Try adding the .length to the lastName in the lesson.

Then, below that enter the console.log( enter the code that has.length)

I hope this helps you.

Happy coding!

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.