gpt4 book ai didi

javascript - javascript中的concat函数?

转载 作者:行者123 更新时间:2023-11-30 09:00:23 25 4
gpt4 key购买 nike

我想从一个数组中选择最大值,所以我使用 math.max 函数,当我只用一个数组运行它时它工作得很好但是因为我有两个不同的数组首先我想把它们连接在一起所以我使用 concat 函数,但它不起作用。

<html xmlns="http://www.w3.org/1999/xhtml">
<head>


<script type="text/javascript">

var maX=[6,1]

var miN=[10,20]

alert(Math.max.apply(maX.concat(miN))


</script>
</head>

<body>
</body>
</html>

最佳答案

apply 接收两个参数:“this”和参数列表。尝试

Math.max.apply(null, maX.concat(miN) )

Math.max.apply(Math, maX.concat(miN) )

关于javascript - javascript中的concat函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9731681/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com