I have a string like
const str = 'Y|NAME|ROLE'
I want to get values after the |icon.
For the first character 'Y' i just used charAt(0) function. How do I get the values like NAME or ROLE no matter what their size
Just split it.
const str = 'Y|NAME|ROLE'; var fields = str.split('|'); console.log(fields[0]);//prints Y console.log(fields[1]);//prints Name console.log(fields[2]);//prints ROLE
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.