Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
I try to push a new value into my array. But when I execute my code an integer is show instead my new array.
var foo = ["Hello"].push(" word"); console.log(foo)
.push()
You should use concat in this context to achieve your goal.
concat
var foo = ["Hello"].concat(" word"); console.log(foo)
Add a comment
That is because you are storing the value that push returns on the variable foo:
foo
The push() method adds one or more elements to the end of an array and returns the new length of the array.
You can do it this way:
var arr = ["hello"]; arr.push(" word"); console.log(arr);
.push()function returns the updated length of the array, and that's of course a number.