split the string
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2017 05:49 AM
Bhagyashree Pradeep Joshi,ggg
var array = name.split(",");
var newname =array[0];
alert(newname);
var name2 = newname.split(" ");
var firstname1 = name2[0];
var lastname2 = name2[1];
alert(firstname1);
alert(lastname2);
here ,alert(firstname1); = Bhagyashree
alert(lastname2); = Pradeep
I want 'bhagyashree' in one variable and 'Pradeep Joshi' in another variable
how to achieve that
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2017 05:53 AM
You simply need to extract the third element of your newname array:
var nextname = name2[2];
Then concatenate those variables:
var another_variable = lastname2 + " " + nextname;
nb: as you're new to scripting, "name", "newname", "firstname1" aren't great variable names.
Also, it's an idea to alert() some text rather than just the variable - if the variable is blank, you'll get some confusing popup. Better to use:
alert("The value of firstname1 is: " + firstname1);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2017 06:50 AM
yup its working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2017 05:54 AM
Hi ,
Whats wrong with the script?? it looks fine, and it works in my demo.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2017 06:08 AM
sharique azim wrote:
Whats wrong with the script??
It doesn't meet his requirements:
Bhagyashree Joshi wrote:
I want 'bhagyashree' in one variable and 'Pradeep Joshi' in another variable