i kinda forget time to time to use .push and rather, i use a simple assignment(=) then throws me an error. when i seek for a hand or remember it’s existence then realize was the only mistake other stuff is quite cool. i wanna ask, what’s the difference btn .push and =??
thank you.
Happy coding
If you have a string or a number or a boolean or a “simple” variable being assigned, use the equals. If, on the other hand, you’re adding some value to the end of an array, you .push()
it onto the array. .push()
, .pop()
, .shift()
and .unshift()
are all functions of the Array class, and don’t apply to simple variables.