这个问题似乎很简单,但我找不到解决办法。 我需要把这个函数的参数(只是数字后面跟着逗号)变成一个满是数字的数组。问题是,参数不是字符串,我无法添加 "" 为了它。如果我 console.log([card]) 只有第一个数字出现在数组(2)中…我试着做一个循环,但没有成功。 谢谢你的帮助!
""
console.log([card])
function cc(card) { } cc(2,3,4,5,6);
无论如何,以防万一,你可以用 arguments 变量:
arguments
var cc = function () { console.log(arguments) }
cc(1,2,3,4,5) 印刷品 Arguments { 0: 1, 1: 2, 2: 3, 3: 4, 4: 5, ⦠} 和 cc(2,3,4,5,6,7,8) 印刷品 Arguments { 0: 1, 1: 2, 2: 3, ⦠}
cc(1,2,3,4,5)
Arguments { 0: 1, 1: 2, 2: 3, 3: 4, 4: 5, ⦠}
cc(2,3,4,5,6,7,8)
Arguments { 0: 1, 1: 2, 2: 3, ⦠}
资料来源: https://gomakethings.com/getting-an-array-of-all-arguments-passed-into-a-function-with-vanilla-javascript/