简体   繁体   English

使用javascript中的关联数组处理拼接

[英]handling splice with associative arrays in javascript

I have an array called as wcs declared using var wcs= new Array(); 我有一个名为wcs的数组,它使用var wcs= new Array(); .

I do add items like this, wcs[indx] = value . 我确实添加了这样的项目, wcs[indx] = value where i will keep on changing the indx value, so at times, my array will be looking like this wcs[2] ='a'; wcs[5]=')'; 我将继续更改indx值,因此有时,我的数组看起来像是wcs[2] ='a'; wcs[5]=')'; wcs[2] ='a'; wcs[5]=')';

when i call the splice method on this array, all the created indices are re-indexed, meaning they become reset from 0... 当我在此数组上调用splice方法时,所有创建的索引都将重新索引,这意味着它们将从0开始重置...

how to avoid this in javascript & jQuery 如何在javascript和jQuery中避免这种情况

Write your own splice method that works the way you want. 编写自己的拼接方法,以所需的方式工作。 If you specify the input, processing and expected output, you might get some help with that. 如果指定输入,处理和预期输出,则可能会获得一些帮助。

If you simply want a copy of the array, you may be after the concat method. 如果您只想要数组的副本,则可以使用concat方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM