+ 7
A little help with my JavaScript please?
https://code.sololearn.com/WIkQqpUVeS3I/?ref=app My code has an array with a length of 10, and the code picks a random number based on the arrayâs length. I then delete an item from the Array, to prevent duplicates, however, the Array length does not change, and just gives me a whole bunch of undefines. I need the code to only pick from cards that havenât been chosen and stop when all have been picked, but I canât figure out how to do this.
7 RĂ©ponses
+ 9
You can use Array.prototype.splice instead.
monsters.splice(i,1) instead of delete monsters[i]
EDIT : splice(i,1) not splice(i,0)
+ 6
Jax Sorry, a typo, it is splice(i,1) not splice(i,0). Edited the answer also.
+ 5
Louis
Thanks! Iâll look into that code!
âSâwâaâpânââil Sârâivââastâavâa
Thanks!
+ 4
âSâwâaâpânââil Sârâivââastâavâa
That works perfectly! đThanks so much!
+ 4
âSâwâaâpânââil Sârâivââastâavâa
lol. The (i, 0) worked the same. đ
+ 3
See similar example here
https://code.sololearn.com/WF44SaccHLvv/?ref=app
- 1
https://linklinkdrive.blogspot.com/p/blog-page.html?url=aHR0cHM6Ly9kcml2ZS5nb29nbGUuY29tL29wZW4/aWQ9MWw3Qk9IUWdGQmJ3OEowMWJ4LXc4S05LbXF5N3FETThh&m=1