(javascript的)拼接是否以某种方式在Firefox 4.0+中被更改/错误
Did (javascript's) splice somehow get changed/bugged in Firefox 4.0+?
根据 http://www.hunlock.com/blogs/Mastering_Javascript_Arrays,这就是我一直用作拼接数组的参考,
// Insert without deleting.
myArray=[1,2,3,4,5,6,7,8,9,10];
newArray = myArray.splice(5,0, '*');
newArray = myArray.splice(4,0, '*');
document.writeln(myArray); // outputs: 1,2,3,4,*,5,*,6,7,8,9,10
但是,在我的代码中,我有:
var myArray=[1,2,3,4,5,6,7,8,9,10];
var newArray = myArray.splice(5,0, '*');
console.log(newArray);
输出为 []
此外,我注意到 myArray 似乎随着 .splice 调用而变化,即使它被分配给 newArray。
1)这是火狐浏览器的错误吗?2) 有没有更好的方法来创建一个添加了 1 个元素的新数组?
提前感谢!
编辑:刚刚注意到我是控制台.log与示例中不同的东西......不过,我问题的第二部分仍然适用 - 我的最新尝试是:
var ints = [91, 44, 67, 80, 91, 52, 68, 50, 50, 32];
var weights = ints;
console.log(weights);
weights = weights.splice(1, 0, 'hey');
console.log(weights);
最终结果仍然是 []
拼接返回删除的元素并修改旧的元素。您正在分配返回的元素(一个空数组)而不是 myArray。
https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/splice
尝试类似的东西
var arrayOne = [1,2,3,4,5];
arrayTwo = arrayOne.slice(0);
arrayTwo.splice(3,0,'Added')
console.log(arrayOne, arrayTwo); // [1, 2, 3, 4, 5] [1, 2, 3, "Added", 4, 5]
相关文章:
- angularjs$valid-on-dates在firefox中报告错误
- $(input[]).仅在firefox中出现每个抛出语法错误
- 在Firefox中导出高图表时出现黑色图像错误
- HTML选择,在DOM中选择了正确的选项,但在firefox中显示了错误的项目
- 尝试getUrl图像时,Firefox WebExtension出现安全错误
- 在firefox中,使用jquery ajax不会调用错误和完整回调
- Javascript代码在chrome和Firefox上给出错误
- 在Firefox中使用锤子捏 错误地定向 - 适用于所有其他浏览器
- jQuery SVG创建折线,firefox错误
- iMacros Firefox错误:“;未终止的字符串文字“;
- 获取 IE 和 Firefox 错误:解析值“xxx”时出错.声明被丢弃
- 使用AngularJS循环访问JSON文件时出现“格式不正确”的Firefox错误
- 如何使用 removeClass 解决状态按钮中的 jquery ui / firefox 错误
- Firefox错误——“底层对象不支持参数或操作”
- 如何在Firefox错误控制台中过滤消息
- 拆分url导致firefox错误
- Firefox错误:如果调整大小:垂直设置焦点,点击事件丢失
- Firefox错误:"TypeError: $it2.hasNext不是一个函数
- 有没有任何方法可以访问Firefox错误'列表
- 内联 JavaScript Firefox 错误