JScript isArray <repost to Ben Roy>

Results 1 to 3 of 3

Thread: JScript isArray <repost to Ben Roy>

  1. #1
    Join Date
    Dec 1969

    Default JScript isArray <repost to Ben Roy>

    I posted something to Ben Roy earlier this morning, and this isn&#039;t working to save my life. Can anyone see why an exception is not being thrown???<BR><BR>function testMe(){<BR>var temp = new Array("dis", "dat");<BR>var temp2 = "";<BR>var temp3; //This is the only one that returns false<BR>var temp4 = 0;<BR>var temp5 = new Array();<BR><BR>alert(&#039;temp is &#039; + isArray(temp));<BR>alert(&#039;temp2 is &#039; + isArray(temp2));<BR>alert(&#039;temp3 is &#039; + isArray(temp3));<BR>alert(&#039;temp 4 is &#039; + isArray(temp4));<BR>alert(&#039;temp5 is &#039; + isArray(temp5));<BR>}<BR><BR>function isArray(myArrayTest){ <BR> try{ <BR> var temp = myArrayTest[0]; <BR> return true;<BR> } <BR> catch (e) { <BR> alert(e);<BR> return false; <BR> } <BR>} <BR><BR>temp3 is the only one that comes back false.. e = &#039;object error&#039;.<BR>I&#039;ve even tried changing this:<BR><BR>var temp = myArrayTest[0]; <BR><BR>to<BR><BR>var temp = myArrayTest.length;<BR><BR>in order to throw an exception. Why won&#039;t this throw an exception?

  2. #2
    Join Date
    Dec 1969

    Default Solution and a NN bug (or design)?

    Well, I found a solution, but when I tested it out in NN4.7, I get this:<BR><BR>JavaScript Error:<BR>http://mypage, line 18:<BR><BR>try is a reserved identifier. <BR><BR> try { <BR>..^<BR><BR>No ****! I know try is a reserved identifier... THAT&#039;S WHAT I&#039;M USING IT FOR!<BR><BR>If anyone could run this in NN other than 4.7, I&#039;d like to see if this is either a bug or just not supported.<BR><BR><BR><BR>Well, the solution... couldn&#039;t figure out why it doesn&#039;t throw an error, so I do it myself:<BR><BR>function isArray(myArrayTest){ <BR>var temp, i;<BR><BR>//alert(myArrayTest[0]);<BR> try { <BR> temp = myArrayTest[0];<BR> if (temp == null)<BR> { <BR> throw &#039;not an array&#039;;<BR> }<BR> return true;<BR> } <BR> catch (e) { <BR> alert(e);<BR> return false; <BR> } <BR>} <BR><BR><BR>Now it works -- though doesn&#039;t seem it&#039;ll be cross browser unfortunately. Seems a bit buggy also because it returns false when you just declare an empty array. Ah well..

  3. #3
    Flurry Guest

    Default Javascript does not support try

    Only Java. Do not use try in your function, and you will not get that error.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts