Length of Last word(javascript)
📰 Medium · JavaScript
Learn to calculate the length of the last word in a string using JavaScript
Action Steps
- Define a function that takes a string as input
- Split the string into an array of words using the split() method
- Access the last word in the array using the index length - 1
- 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 »
DeepCamp AI