javascript - How can I get data out of a string of roles separated with colons? -
i have java string user role info separated colons. variable a contain info this:
var = "admin:xxxx:data"; var = "xxxx"; var = "test"; var = "admin" i need set variable based on formula depends on test, xxx , info roles beingness nowadays or not. note have check in place ensure test , xxxx cannot both nowadays , @ to the lowest degree 1 of them must present.
index = 0 if 'test' role appears index = 1 if 'xxxx' role appears index = 100 if 'test' , 'data' role appear index = 101 if 'xxxx' , 'data' roles appear plus 4 variables:
isxxxx = true if xxxx appears isdata = true if info appears istest = true if test appears isadmin = true if admin appears is there simple way code this. right not sure illustration how out individual roles variable if advise me on plenty me going.
based on fact have used var initialize variables, i'm assuming have javascript , not java code. aside that, this:
var = "admin:xxxx:data"; var parts = a.split(':'); for(part in parts) { console.log(parts[part]); } this code splits string on : , loops on parts.
also, wanted point out you're defining var a 3 times , isn't necessary. additionally, you're overwriting existing value of a each assignment.
javascript
No comments:
Post a Comment