Slice to collect part of a String
var my_str="Welcome to www.plus2net.com";
The above code will display Welcome. We can start the slice from by living last 7 characters of the string by using negative number as p2. Let us remove last 7 characters of the string by using negative number as -7. Here is the code.
var my_str="Welcome to www.plus2net.com"
The output of the above code will be Welcome to www.plus2 , you can note that the last 7 characters of the main string is removed ( sliced ).
Now let us try to collect userid and domain part of an email address by using slice and indexof function.
Be the first to post comment on this article :