Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

splice and split arrays

Status
Not open for further replies.

cathiec

Programmer
Oct 21, 2003
139
IE
for(var j=0;j<3;j++){

var thisOne = Math.floor(Math.random( )* allNums.length);
ran_number=allNums[thisOne];
allNums.splice(thisOne,1);
ran_number = ran_number + &quot;&quot;;
for(var i = tbl.rows.length-1; i >=0; i--){
if(tbl.rows.id == ran_number){
tbl.deleteRow(i);
alert(ran_number);

}
}

i want to split the array allNums and when i use the following code i get an error: Object does not support this property or method:

var splitString = new Array();
splitString = allNums.split(&quot;,&quot;);
alert(splitString[0]);
alert(splitString[1]);
alert(splitString[2]);
alert(splitString[3]);
alert(splitString[4]);
 
I threw together this example of an array creation
and usage of your code:
Code:
<html><head><script>
var allNums = new Array(1,2,3);
function ckarray() {
for(var j=0;j<3;j++){
  var thisOne = Math.floor(Math.random( )* allNums.length);
   if(thisOne<0) {thisOne = 0;}
  ran_number=allNums[thisOne];
  allNums.splice(thisOne,1);
  ran_number = ran_number + &quot;&quot;;
  alert('ran_number is ' +ran_number); alert('allNums length is ' +allNums.length);}
}
</script></head><body>
<a href=&quot;#&quot; onClick=&quot;javascript:ckarray();&quot;>TEST</a>
</body></html>

Also the way you are using split is for a string object
not an array, if your intention is to create the allNums
array using split this is the how you would do that.

var str = '1,2,3';
var allNums = str.split(&quot;,&quot;);
then you have an array but usage here would need to
be joined with usage of parseInt because you originally
declared these values as a string.

2b||!2b
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top