var myList = ["Hello There World", "meatball", "cookie monster"];
var BreakUpFirst = function (myList) {
document.write(myList[0].split(" "));
};
Hello I am new to JavaScript so please bear with me. Not sure what I am doing wrong here.
I am trying to break the first string in the myList array into its own array with 3 values. The split method works fine for me outside of the function, but I can't get it to work inside. I want to create BreakUpFirst as a new array and keep myList or any other array I pass through it as is.
var BreakUpFirst = myList[0].split(" ");?BreakUpFirst()afterwards somewhere to actually RUN the code...myListarray you've already defined, takemyListout of your function definition so it just readsvar BreakUpFirst = function() {Alternative, you can invoke your function as indicated in my answer below, passing in the global variable.