Javascript Split problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DannyMc
    New Member
    • Aug 2007
    • 20

    Javascript Split problem

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

    Code:
       var myString = (str);
    	   var myTemp1 = myString[11].split(",",1);
    	   var myTemp2 = new Array();
    	   myTemp2 = myTemp1.split("=",2);	
    		var myManager = myTemp2[1];
    I managed to get the value from myTemp1(tried it) but i have problem with
    Code:
    myTemp2 = myTemp1.split("=",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
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    myTemp1 is an array, not a string. Use an index into the array and then call split() on that.

    Comment

    • DannyMc
      New Member
      • Aug 2007
      • 20

      #3
      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?

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Originally posted by DannyMc
        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.

        Comment

        Working...