Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Remove All Strings From Array, But Keep Strings With Specific Length in JavaScript

I am trying to make Wordle in React. For that I need a list of Strings. I am getting an array of strings from this API: https://random-word-api.herokuapp.com/all

The problem is that I don’t want every word. I only want words that has a length of 5. How do I remove all the strings that doesn’t have a length of 5 from the array?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Assuming you have an array of words, words, use Array#filter.

const fiveLetterWords = words.filter(w => w.length === 5)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading