Click here to Skip to main content
15,667,475 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
var myArray = [];
myArray = ["Tayfur Gazioglu", "tayfurgazioglu"];

function cutName(name)

   var cut = name[0].split(" ");
  return cut;

var myInfo = {
fullName : cutName[myArray],
skype : myArray[1],
github : 'tayfurgazioglu'


What I have tried:

There is something wrong with the function cutName! I tried the samething without the function, it works. But when i try like this the value of document.write(myInfo.fullName); is undefined.
Updated 30-Mar-17 9:08am

fullName : cutName[myArray]

you are calling this function in wrong way. lets stick to the basics and call it something like this
fullName : cutName(myArray[0])
Share this answer
function cutName(name) {

           var cut = name[0].split(" ")[0];
           return cut;

fullName: cutName(myArray),
Share this answer
Other CP members already pointed it out the correct way to call the function is
fullName : cutName(myArray)

Another tip I wanted to throw in is the full name formatting, this way the function will return "Firsname, Lastname" VS "Firstname,Lastname"

return cut[0] + ', ' + cut[1]; 
//cut[1] + ', ' + cut[0];
//cut[0] + ' ' + cut[1]

OR, this method, you don't have the control to arrange the name.
return cut.join(", ");
//cut.join(" "); 


cutname - JSFiddle[^]
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900