gpt4 book ai didi

javascript - 为什么 new Array(4).join ("ha") 产生 "hahahaha"而不是 "undefinedhaundefinedha .."

转载 作者:数据小太阳 更新时间:2023-10-29 06:14:05 27 4
gpt4 key购买 nike

为什么 new Array(4).join("ha") 产生“hahaha”而不是“undefinedhaundefinedha .. “?

var arr = new Array(4);
alert( arr[0] ); // produces `undefined`

最佳答案

undefinednull 的数组元素被转换为空字符串。 It's right there in the documentation.

If an element is undefined or null, it is converted to the empty string.

关于javascript - 为什么 new Array(4).join ("ha") 产生 "hahahaha"而不是 "undefinedhaundefinedha ..",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55405532/

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