substring - Javascript - cutting out part of a string -
hello everyone,
i'm trying find best way cut out specific parts of below input string. i'm using white space (' ') separator. i'm unable cut out required parts , assign them respective variables.
var input = "/w user1 message" var user = input.substring(2, input.indexof(' '));?? var message = ??? expected result:
user = "user1" message = "message" it works when empty spaces replaced coma or other separator.
is there specific reason why iit's not working spaces?
thanks in advance, alex
i recommend using split, creates array , can access array index
var input = "/w user1 message" var inputparts = input.split(' '); var message = inputparts[2]; console.log(message);
Comments
Post a Comment