1 year ago

#14924

test-img

Cat_Mommy

Splice Array at unknown position

I'm fairly new to Typescript and currently I'm trying to program a Usermanager. My issue is when I want to update a specific user it's not working correctly, as it's always targeting the first user in my array and not the one I actually want to edit. That is my code:

const index: number = Number (target.dataset["user"]);

userdata.splice(index, 1, new User(mail.value, lastname.value, firstname.value, pwd.value));

My IDE usually tells me that the first number is "start" and the second "delete count" but in this case it doesn't. So I'm assuming my indexis not correct somehow. I tried different ways to declare it but nothing works for me. To be clear what I mean: e.g. userdata.splice( start: 0, deleteCount:1, ...) would be the way my IDE displays this line if I put a number as start index but the way my code is it's: userdata.splice (index, deleteCount:1,...) which is why I'm thinking that my declaration of index is not correct.

typescript

array-splice

0 Answers

Your Answer

Accepted video resources