为什么此代码打印出 4
而不是 ['B', 'e', 'e', 'a']
?
var word = 'Bee';
var letters = word.split('').push('a');
console.log(letters);
// -> 4
最佳答案
如下所述:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push
The push() method adds one or more elements to the end of an array and returns the new length of the array.
这就是为什么字母
分配为数字
而不是数组。
关于javascript - 为什么这会返回一个数字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41008076/