Stanislas πŸ‘¨β€πŸ’» (elefantinho) is a user on mstdn.io. You can follow them or interact with them if you have an account anywhere in the fediverse. If you don't, you can sign up here.
Stanislas πŸ‘¨β€πŸ’» (elefantinho) @angristan

Need JS help. Am I missing something?

Β· Web Β· 0 Β· 0

@angristan splice mutates the original array, so there is no need to assign to str. i dont remember what the return value of splice is but it maybe be the empty array you see

@angristan Do not assign the output of Array.splice().

foo = [];
foo.splice(0,0,'a');
console.log(foo); // ['a']

That's why I was asking in the first place, and I was using splice correctly
I didn't understand why my function didn't do anything.. I thought that splice wasn't usable with variables or something?!

Turns out I was replacing each character with itself... :grodoudou2:

(first screen = dumb, second = ok)

@angristan All right, just because it wasn't clear :) It's funny, and welcome into JS world :p

@angristan It's quite different, and JS isn't as strict as C… I'm quite addict to "use strict" in JS files :D

@Sp3r4z C is interesting for this (and type, and pointers) but... ugh :blobsweats:

@angristan "this" like the class itself in PHP, JS… ? :o

@angristan Ahah right :3
Sure it is, maybe too much sometime, for begginers :/

@Sp3r4z I discovered "use strict" yesterday but didn't take a look at it yet!

@angristan Really funny, it's quite interesting just testing "small JS file" wth a "use strict" on top… Most of the time, lot of problem exists :/