开发者

How to reset a list

It might be a silly question but still i am facing problem with this.

  var eformDet开发者_运维百科ailIds = []; 


eformDetailIds=$("[name=eform_id]").map(function(){ return $(this).val() }).get();  

this is the code that i have written in js function and calling this function on button click.

But the problem is the list eformDetailIds containing the previous values also. could you please how to set this empty list for every function call? Thanks in advance.


Just set the length to zero:

eformDetailIds.length = 0;

Or allocate a new array:

eformDetailIds = [];

Now, that said, according to the code you posted the entire array will definitely be replaced each time that ".map()" call runs. In other words, the previous values will not remain in the array. Perhaps you should post more to explain what it is that makes you think the old values remain.


Don't forget you can always reset the array in this way:

myArray = new Array();

It is pretty easy.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜