I am trying to create a function which uses a parameter which will split up items. The split part works, but the problem is when I try to use an item from an array, I get undefined.
var arrayItems = ["twenty two","thirty three","forty four","fifty five"];
function splitElement(arr) {
arr.split(" ");
return arr;
}
splitElement(arrayItems[0]);
Unfortunately this returns twenty two instead of ["twenty","two"]
As a test, I tried this and it does return what I want:
function splitElement(arr) {
arr = arrayItems[0].split(" ");
return arr;
}
splitElement();
But what I want to do now is to grab any element from the array as a parameter and leave arr as the wildcard which can accept any input parameter for the output.
For example, if I did this:
splitElement("sixty six");
then it should return an array:
["sixty","six"];
What am I doing wrong?