我正在玩数组以及方法和函数,并希望打印以下字符串
马克屠夫
var mack = [];
function newMack(){
mack.push("Mack", "the", "butcher");
mack.join(" ");
};
alert(newMack());
我越来越不确定,我不知道我在做什么错。
这是现场
https://jsfiddle.net/1hn5d05k/
最佳答案
尝试从函数中return
处理后的结果,
return mack.join(" ");
DEMO
如果没有从没有使用
new
关键字调用的函数中返回任何内容,则将返回undefined
。请参阅此处的documentation。关于javascript - 使用方法和数组“Mack the butcher”字符串,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36957698/