JavaScript Array Question

why is this array not showing the information of itself
No description
7 Replies
Jochem
Jochem3w 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
عبد الحي
i tried to do this finalArr = [arrOne,arrTwo] and the same result happend
Jochem
Jochem3w 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
عبد الحي
OHHHHHHHHHHHHH MYYYYYYYYYY GOOOOOOOOOOOOOOOOD IT WORKED IS THAT A CHEAT CODE
Jochem
Jochem3w ago
It's just a language feature
Mannix
Mannix3w ago
there is also concat() method 🙂
ἔρως
ἔρως3w ago
and there's a mix of both: .unshift(...array2)