简体   繁体   中英

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

您必须使函数splitName return final_string;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM