Javascript 我的解决方案有什么问题,加入数组元素?
我是JavaScript新手,如果这个问题很愚蠢,我很抱歉 任务: 声明一个名为join的函数,该函数可以接受两个输入:1是数组,2是分隔符字符串。分隔符字符串是可选的 join将输入数组的所有元素与输入字符串连接起来,并返回结果。join的输出总是一个字符串 这是我的代码,但它没有传递,我做错了什么Javascript 我的解决方案有什么问题,加入数组元素?,javascript,arrays,javascript-objects,Javascript,Arrays,Javascript Objects,我是JavaScript新手,如果这个问题很愚蠢,我很抱歉 任务: 声明一个名为join的函数,该函数可以接受两个输入:1是数组,2是分隔符字符串。分隔符字符串是可选的 join将输入数组的所有元素与输入字符串连接起来,并返回结果。join的输出总是一个字符串 这是我的代码,但它没有传递,我做错了什么 var myName = ["firstname", "lastname"]; function join(arr, separator) { console.log(join.split)
var myName = ["firstname", "lastname"];
function join(arr, separator) {
console.log(join.split)
}
错误是:join函数用给定的分隔符字符串连接给定数组的项
提前谢谢你的帮助 您的函数当前不处理传入的参数,并且不返回任何内容。 我用一个小例子来说明我的意思。我希望它能帮助你完成作业
var myName = ['firstName', 'lastName'];
function join(arr, separator) {
var result;
// Do something with arr and separator, in this case I log it
console.log(arr, separator);
// return the result, in this case it should be the string you need to build
return result;
}
// Call the function to test it
// join(['hello', 'world'], ', ') should output "Hello, world"
============
Example:
function multiply(number, times) {
return number * times; // this returns the multiplication
}
multiply(5, 10); // 50
function multiply2(number, times) {
number * times; // This doesn't return anything
}
multiply2(3999, 1234); // undefined