G
Gary N.
Hi -
I'm not sure if I've found a bug with the "splice" function or if I just
need better documentation. Splice doesn't work quite how O'Reilly describes
it (Javascript, 4th edition, Jan 2002, section 9.2.6, pg 144). I'm using
IE6.
var a = new Array( 1,2,3,4,5 );
document.write( a.splice( 0 ) ); // returns "", should return "1,2,3,4,5"
It works when you add the (supposedly optional) second argument. For
example:
a.splice( 0, a.length ); // returns "1,2,3,4,5"
Is this a known bug/feature? Is there a good javascript reference site?
Thanks for the help!
Gary
Here is a short block of code:
<SCRIPT language='javascript'>
function testSplice() {
var sample = new Array( 1,2,3,4,5 );
parent.document.write( 'doesn\'t work = ' + sample.splice( 0 ) + '<br>' );
parent.document.write( 'works fine = ' + sample.splice( 0, sample.length )
+ '<br>' );
}
</SCRIPT>
<HTML>
<BODY onload="testSplice();">
text
</BODY>
</HTML>
I'm not sure if I've found a bug with the "splice" function or if I just
need better documentation. Splice doesn't work quite how O'Reilly describes
it (Javascript, 4th edition, Jan 2002, section 9.2.6, pg 144). I'm using
IE6.
var a = new Array( 1,2,3,4,5 );
document.write( a.splice( 0 ) ); // returns "", should return "1,2,3,4,5"
It works when you add the (supposedly optional) second argument. For
example:
a.splice( 0, a.length ); // returns "1,2,3,4,5"
Is this a known bug/feature? Is there a good javascript reference site?
Thanks for the help!
Gary
Here is a short block of code:
<SCRIPT language='javascript'>
function testSplice() {
var sample = new Array( 1,2,3,4,5 );
parent.document.write( 'doesn\'t work = ' + sample.splice( 0 ) + '<br>' );
parent.document.write( 'works fine = ' + sample.splice( 0, sample.length )
+ '<br>' );
}
</SCRIPT>
<HTML>
<BODY onload="testSplice();">
text
</BODY>
</HTML>