By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,117 Members | 2,093 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,117 IT Pros & Developers. It's quick & easy.

Javascript Split problem

P: 20
Hi, I have written a code to split the string and here is the code.

Expand|Select|Wrap|Line Numbers
  1.    var myString = (str);
  2.        var myTemp1 = myString[11].split(",",1);
  3.        var myTemp2 = new Array();
  4.        myTemp2 = myTemp1.split("=",2);    
  5.         var myManager = myTemp2[1];
  6.  
I managed to get the value from myTemp1(tried it) but i have problem with
Expand|Select|Wrap|Line Numbers
  1. myTemp2 = myTemp1.split("=",2);    
  2.  
In FireFox Error Console show the error message :
Error: myTemp1.split is not a function.

Why the browser treat it as function? Please advice.

Thank you
Jan 9 '08 #1
Share this Question
Share on Google+
3 Replies


acoder
Expert Mod 15k+
P: 16,027
myTemp1 is an array, not a string. Use an index into the array and then call split() on that.
Jan 9 '08 #2

P: 20
Thank you for the solution, it works!

I thought myTemp1 supposed to be string, because i only assigned 1 variable to it. How come it is still array?
Jan 11 '08 #3

acoder
Expert Mod 15k+
P: 16,027
I thought myTemp1 supposed to be string, because i only assigned 1 variable to it. How come it is still array?
split() produces an array from a string, not an array. It's not still an array. myString[11] is a string. If you call split() on that string, the result is an array.
Jan 11 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.