array object remove

Hey, I'd like some help I've been trying things for the past 30 mins and I jsut can't figure it out! I've completely made the add, create, delete functions they all work as they are supposed to UNTIL I remove the first object, then it all goes to shit and no longer functions and I just can't figure out why tf this is happening Whenever I look at the console.log(articles) in the console while messing around it ALWAYS returns the correct amount of objects in the array UNTIL I even dare remove the first object, then it just breaks apart and the first object that's supposedly removed persists within the array Yet every other element gets removed as intended, I don't get why this very first object is messing it up I can edit its data as much as I want, no issues but when I delete it, it just messes everything up and the deletion is just a compare(a,b, index) if(a==b)articles.splice(index,index) Can someone please save my soul If you want to fiddle around, here's the link https://brights-store-app-prototype.netlify.app (for those who don't speak dutch and prefer fiddling around to figure out whats making this happen; "opslaan" means save, clicking this will commit the changes "annuleer" means cancel)
14 Replies
Brightie
BrightieOP•12mo ago
nvm, now more things have broken in this... even tho I didn't make anymore changes between testing local and pushing it.. xd
MarkBoots
MarkBoots•12mo ago
splice takes in the start index and the count. so splice(index, 1) will remove the selected index otherwise, if you put in splice(index, index). it will remove 0 from index 0
Brightie
BrightieOP•12mo ago
so basically, all I should do is change that and it would solve it? let me give it a go I swear if that fixes this entire mess then idek xd
MarkBoots
MarkBoots•12mo ago
i didnt look at your project yet. but I noticed that from what you posted here
Brightie
BrightieOP•12mo ago
Im going to scream... So I've been looking for half an hour just bc i did index index instead of idnex 1 that indeed made it stop persisting and its now working just fine...
MarkBoots
MarkBoots•12mo ago
well, it happens
Brightie
BrightieOP•12mo ago
couldve been looking and trying for years like that 😂 thanks hey hold on, it sometimes still seem to delete 2 at once... but only after Ive atleast once completely emptied the list I mean, atleast it doesn't cause it to crash... but I find it odd any clue why that is happening? adding them seems to work fine but deleting them acts odd Okay something truely peculiar is happening... so, casually fiddling around with it right It broke (like it was like "this doesnt exist you cant remove it) so i add one more, n try deleete the new one, does it just fine then Im like okay now lets remove the one that was already here, still says it doesnt exist so creating a new one again and then it is able to delete both what
MarkBoots
MarkBoots•12mo ago
you have to rethink your logic when you create the cards, they get an evenlistener with a reference to the index at that moment in time. but when you delete from the article array, those references do not match anymore give each an id and use that to select (filter/findIndex method on the array) and remove it
Brightie
BrightieOP•12mo ago
Well, I've basically changed every reference to be looking for the articles.articleHope because articleHope would be a non-duplicate It can only exist once which is why I find it odd that it acts up and what I find even stranger is that it only starts acting up the moment ive completely emptied out the list atleast once
MarkBoots
MarkBoots•12mo ago
console log is your best friend. take some time. unfortunatly i don't have the time to dive into it too much
Brightie
BrightieOP•12mo ago
Yeh Unless the issue lies in the fact that while fiddling around I'm simply leaving the hope blank, so it is having duplicates Maybe that is messing with it, I'm not sure tho Anyway thanks for the help so far and happy holidays it may accidently sometimes remove 2 bc they have the same hope number and its comparing hpe numbers to look for what to delete but visually it only removes 1
MarkBoots
MarkBoots•12mo ago
tip. play around with some simplified data (without the distraction of other content)
Brightie
BrightieOP•12mo ago
as the thing that gives the digit in the top is simply updating the articles.length() (that jumped w 2 at once, which is why I noticed something strange happening in the backside) so something is causing the delete function to run twice or to take multiple objects, ill lookinto it yeah okay, its something to do with duplication as now ive made sure to actually give it some data so its not a duplicate n now its not running into the issues
MarkBoots
MarkBoots•12mo ago
here a really simple example. (that's all I can do for today) https://codepen.io/MarkBoots/pen/vYPEZpy?editors=1011
Want results from more Discord servers?
Add your server