Javascript未定义的值 [英] Javascript undefined value
问题描述
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'
};
document .write(myInfo.fullName);
我尝试过:
函数cutName有问题!我试过没有这个功能的同样的东西,它的工作原理。但是,当我尝试这样的document.write(myInfo.fullName);未定义。
fullName:cutName [myArray]
你打电话这个功能错误的方式。让我们坚持基础并称之为这样的事情
fullName:cutName(myArray [ 0 ])
更正
function cutName(name){
var cut = name [0] .split()[0];
退货;
}
fullName:cutName(myArray),
其他CP成员已经指出了调用该函数的正确方法是
fullName: cutName(myArray)
我想要输入的另一个提示是全名格式化,这样函数将返回Firsname,Lastname VS名字,姓氏
<前lang =Javascript> 返回 cut [ 0 ] + ' ,' + cut [< span class =code-digit> 1 ];
// cut [1] +','+ cut [0];
// cut [0] +''+ cut [1]
或者,这个方法,你没有控制来安排名字。
return cut.join( ,);
// cut.join();
示例:
cutname - JSFiddle [ ^ ]
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'
};
document.write(myInfo.fullName);
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.
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])
correction
function cutName(name) { var cut = name[0].split(" ")[0]; return cut; }
fullName: cutName(myArray),
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(" ");
Example:
cutname - JSFiddle[^]
这篇关于Javascript未定义的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!