Problem in splice() event in javascript.(Help)![Solved] | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

Problem in splice() event in javascript.(Help)![Solved]

Here is a sample code of mine😇,and as u could see it displays circle particles which shrink...so I want to delete the particles when they are less that 0.3 in size....I have it by splice() but it does not work...... Please change the splice() event to a proper working way which is inside handleParticles function....and aslo I have marked with a commented line on where I need to be changed ... So please give me a solution on how to fix it.. ------------------ (For further understanding) I need the particles to be deleted when the are less than or equal to 0.3 in size...so I've made a splice event on particleshandle function...but it does not work....so please give me an answer...😇 Hope u understand!😁 https://code.sololearn.com/W6lbAcSG4n5e/?ref=app

14th Mar 2021, 11:54 AM
•Đคяк รтяεคм 𝅘𝅥𝅮 ᴺ•ᵀ•ᴬˢᵘʳᵃᵖᵖᵘˡᶦ
•Đคяк รтяεคм 𝅘𝅥𝅮 ᴺ•ᵀ•ᴬˢᵘʳᵃᵖᵖᵘˡᶦ - avatar
7 Answers
14th Mar 2021, 12:18 PM
visph
visph - avatar
+ 2
as you want to delete items while iterating, you must reverse iterate, else indexes will be modified as soon as a first item is removed: function handleParticles(){ // for(let i = 0; i < particlesArray.length; i++){ let i=particlesArray.length; while (i--) { // your code
14th Mar 2021, 12:04 PM
visph
visph - avatar
+ 2
Thank u,it works perfectly 😊👍😇
14th Mar 2021, 4:02 PM
•Đคяк รтяεคм 𝅘𝅥𝅮 ᴺ•ᵀ•ᴬˢᵘʳᵃᵖᵖᵘˡᶦ
•Đคяк รтяεคм 𝅘𝅥𝅮 ᴺ•ᵀ•ᴬˢᵘʳᵃᵖᵖᵘˡᶦ - avatar
+ 1
Still didn't work🤕!
14th Mar 2021, 12:15 PM
•Đคяк รтяεคм 𝅘𝅥𝅮 ᴺ•ᵀ•ᴬˢᵘʳᵃᵖᵖᵘˡᶦ
•Đคяк รтяεคм 𝅘𝅥𝅮 ᴺ•ᵀ•ᴬˢᵘʳᵃᵖᵖᵘˡᶦ - avatar
+ 1
Umm,but they still particles could be seen tiny .....I want them to deleted....😇?
14th Mar 2021, 1:36 PM
•Đคяк รтяεคм 𝅘𝅥𝅮 ᴺ•ᵀ•ᴬˢᵘʳᵃᵖᵖᵘˡᶦ
•Đคяк รтяεคм 𝅘𝅥𝅮 ᴺ•ᵀ•ᴬˢᵘʳᵃᵖᵖᵘˡᶦ - avatar
+ 1
I could still see them when in 0.1 size...so I want that also to reduce(deleted so cannot see those)
14th Mar 2021, 1:38 PM
•Đคяк รтяεคм 𝅘𝅥𝅮 ᴺ•ᵀ•ᴬˢᵘʳᵃᵖᵖᵘˡᶦ
•Đคяк รтяεคм 𝅘𝅥𝅮 ᴺ•ᵀ•ᴬˢᵘʳᵃᵖᵖᵘˡᶦ - avatar
+ 1
updated my code: you must check particlesArray[i].size rather than particlesArray[i], and only update/draw if check is false...
14th Mar 2021, 1:44 PM
visph
visph - avatar