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

How to get a String out of a String[] with startsWith

Im trying to get a string that startsWith "O-" out of a string[] but don’t know how

const players = Array.from(world.getPlayers())
    for (let player of players) {
        let tags = player.getTags() // tags is the Array
        
        let tag = tags.startsWith("O-")
        
    }

>Solution :

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

Assuming player.getTags returns an array of strings, and you only want a single tag, you can use the find method, and pass to it a function that checks if a tag starts with "O-".

let tag = tags.find(t => t.startsWith("O-"))
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