Appearance
let newList = [1, 2, 3].push(4) console.log(newList.push(5))
A. [1, 2, 3, 4, 5] B. [1, 2, 3, 5] C. [1, 2, 3, 4] D. Error
答案: D
.push方法返回数组的长度,而不是数组本身! 通过将newList设置为[1,2,3].push(4),实际上newList等于数组的新长度:4。 然后,尝试在newList上使用.push方法。 由于newList是数值4,抛出TypeError。
.push
newList
[1,2,3].push(4)
4