I have this string:
var fruits = "banana,apple";
var newFruit = "orange";
fruits
.split(",")
.push(newFruit);
fruits.split(",")
push()
split
does return a normal array. You are successfully calling push
on it.
The problem is that you are then discarding the array so you can't do anything further with it.
Since push
doesn't return the array itself, you have no way of using the array for anything further after calling push
on it.
concat
returns a new array that contains the additional values, but you would still have to do something with the array afterwards.
var fruits = "banana,apple";
var newFruit = "orange";
var myArray = fruits
.split(",")
.concat(newFruit);
console.log(myArray);