JavaScript Array Question

why is this array not showing the information of itself
No description
7 Replies
Jochem
Jochem6mo ago
that's not how unshift works. Unshift puts the arguments into the array, and you're feeding it two arrays, which puts each array (not the elements in the array, but the array itself) into the finalArr
محمد
محمدOP6mo ago
i tried to do this finalArr = [arrOne,arrTwo] and the same result happend
Jochem
Jochem6mo ago
that's the same thing, yeah you need to use the spread operator in this case
let finalArr = [...arrOne, ...arrTwo];
let finalArr = [...arrOne, ...arrTwo];
that puts all the elements into the new array rather than the array itself into a nested array
محمد
محمدOP6mo ago
OHHHHHHHHHHHHH MYYYYYYYYYY GOOOOOOOOOOOOOOOOD IT WORKED IS THAT A CHEAT CODE
Jochem
Jochem6mo ago
It's just a language feature
Mannix
Mannix6mo ago
there is also concat() method 🙂
ἔρως
ἔρως6mo ago
and there's a mix of both: .unshift(...array2)
Want results from more Discord servers?
Add your server