Stuart G
Stuart G

Reputation: 185

Getting Undefined in object literal when the result should be simple

So this is super simple stuff but for some reason i cant figure out what i am doing wrong. My hash simply wont return the output of my function. any help would be greatly apperciated

myArray = ["firstname lastname", "emailadress"];
var splitName = function(string){ 
    var final_string = string.split(" ");
  console.log(final_string);
};
var result = splitName(myArray[0]);

console.log(result); // this returns undefined 

myData = {
fullName : splitName(myArray[0]), 
};
console.log(myData); //still returns undefined

Upvotes: -1

Views: 82

Answers (1)

Firedrake969
Firedrake969

Reputation: 773

You have to make the function splitName return final_string;

Upvotes: 4

Related Questions