This question already has an answer here:
- How to check if an object is an array? 44 answers
I have the following variables which are arrays:
const gumBrands = ['orbit', 'trident', 'chiclet', 'strident'];
const mintBrands = ['altoids', 'certs', 'breath savers', 'tic tac'];
Below I have the following function that uses the variables as input arguments:
function shallowCopy (arrOne, arrTwo) {
if (arrOne.constructor === 'Array'){
return [...arrOne, ...arrTwo];
}
else {
console.log('test this');
}
}
shallowCopy(gumBrands, mintBrands)
I am expecting my code to return:
[ 'orbit',
'trident',
'chiclet',
'strident',
'altoids',
'certs',
'breath savers',
'tic tac' ]
Instead the code runs my else statement and returns: test this
What am I doing wrong?
Aucun commentaire:
Enregistrer un commentaire