【发布时间】:2019-11-12 13:03:09
【问题描述】:
我有以下变量是数组:
const gumBrands = ['orbit', 'trident', 'chiclet', 'strident'];
const mintBrands = ['altoids', 'certs', 'breath savers', 'tic tac'];
下面我有以下使用变量作为输入参数的函数:
function shallowCopy (arrOne, arrTwo) {
if (arrOne.constructor === 'Array'){
return [...arrOne, ...arrTwo];
}
else {
console.log('test this');
}
}
shallowCopy(gumBrands, mintBrands)
我期待我的代码返回:
[ 'orbit',
'trident',
'chiclet',
'strident',
'altoids',
'certs',
'breath savers',
'tic tac' ]
代码运行我的 else 语句并返回:test this
我做错了什么?
【问题讨论】:
标签: javascript arrays function if-statement arguments