Length of Last word(javascript)

📰 Medium · JavaScript

Learn to calculate the length of the last word in a string using JavaScript

beginner Published 28 Jun 2026
Action Steps
  1. Define a function that takes a string as input
  2. Split the string into an array of words using the split() method
  3. Access the last word in the array using the index length - 1
  4. Return the length of the last word using the length property
Who Needs to Know This

This task is beneficial for frontend engineers and developers who work with strings in JavaScript, as it helps them understand basic string manipulation techniques.

Key Insight

💡 Use the split() method to divide the string into words and access the last word's length

Share This
💡 Calculate the length of the last word in a string with JavaScript!

Key Takeaways

Learn to calculate the length of the last word in a string using JavaScript

Full Article

Given a string s consisting of words and spaces, return the length of the last word in the string. Continue reading on Medium »
Read full article → ← Back to Reads