Array对象中是否有'remove()'方法? [英] Is there any 'remove()' method in Array object?
问题描述
嗨伙计:
我一直在寻找(也就是谷歌搜索)没有成功。
我需要超出''流行音乐的可用性( )''删除数组时的方法
元素。例如:
oName = new Array(''Lucas'',''Brasilino'',''Silva'');
oName.remove (''Brasilino'');
oName.toString(); //推出''卢卡斯,席尔瓦''
任何花哨的功能让我把它添加为''remove()''方法??
>
提前多多谢谢。
Bests问候
Lucas Brasilino
br ******* @ yahoo.com 写道:
嗨伙计:
我一直在寻找(也称谷歌搜索)没有成功。
删除数组
元素时,我需要超出''pop()''方法的可用性。例如:
oName = new Array(''Lucas'',''Brasilino'',''Silva'');
oName.remove (''Brasilino'');
oName.toString(); //推出''卢卡斯,席尔瓦''
任何花哨的功能让我把它添加为''remove()''方法??
>
非常感谢。
Bests问候
Lucas Brasilino
您可以使用Array.splice()方法。
splice方法将索引作为参数启动
删除元素和数字要删除的元素。例如,
你的情况:
var arrNames = new Array(Lucas,Brasilino,Silva);
arrNames.splice(1,1); //从索引1开始,删除1个元素。
web.dev D?D°D?D ?? ?D°D2:
br*******@yahoo.com 写道:
嗨人们:
我一直在寻找(也就是谷歌搜索)没有成功。
删除数组
元素时,我需要超出''pop()''方法的可用性。例如:
oName = new Array(''Lucas'',''Brasilino'',''Silva'');
oName.remove (''Brasilino'');
oName.toString(); //推出''卢卡斯,席尔瓦''
任何花哨的功能让我把它添加为''remove()''方法??
>
非常感谢。
Bests问候
Lucas Brasilino
您可以使用Array.splice()方法。
splice方法将索引作为参数启动
删除元素和数字要删除的元素。例如,
你的情况:
var arrNames = new Array(Lucas,Brasilino,Silva);
arrNames.splice(1,1); //从索引1开始,删除1个元素。
Probabely .splice()是最佳选择。
或者你可以使用删除关键字:
删除arrNames [1]
然后数组中的索引将被破坏(0,然后是2,没有1)
和只能使用for(......在
....中)列出aray {}}
sc********@gmail.com 写道:
或者你可以使用删除关键字:
删除arrNames [1]
然后数组中的索引将被破坏(0,然后是2,没有1)
指数不会被破坏。 - 它们一直从0到现有的
数组长度,但数组内部会得到一个非实例化的(未定义的)
成员。
>
OP真正寻找的不是数组而是Vector数据类型但是
JavaScript没有这样的数据类型(虽然它可以通过
$ b模拟$ b不同的意思)。
继续使用数组技术切片/拼接方法将是
确实是最好的选择。
Hi Folks:
I''ve been looking (aka googling) around with no success.
I need a usability beyond ''pop()'' method when removing an Array
elements. For example:
oName = new Array(''Lucas'',''Brasilino'',''Silva'');
oName.remove(''Brasilino'');
oName.toString(); // puts out ''Lucas,Silva''
Any fancy function to me to add this as a ''remove()'' method ??
Thanks a lot in advance.
Bests regards
Lucas Brasilino
br*******@yahoo.com wrote:Hi Folks:
I''ve been looking (aka googling) around with no success.
I need a usability beyond ''pop()'' method when removing an Array
elements. For example:
oName = new Array(''Lucas'',''Brasilino'',''Silva'');
oName.remove(''Brasilino'');
oName.toString(); // puts out ''Lucas,Silva''
Any fancy function to me to add this as a ''remove()'' method ??
Thanks a lot in advance.
Bests regards
Lucas BrasilinoYou can use the Array.splice() method.
The splice method takes as arguments an index which you want to start
removing elements and the number of elements to remove. For example in
your case:
var arrNames = new Array("Lucas", "Brasilino", "Silva");
arrNames.splice(1, 1); //start at index 1, remove 1 element.
web.dev D?D°D?D???D°D2:br*******@yahoo.com wrote:Hi Folks:
I''ve been looking (aka googling) around with no success.
I need a usability beyond ''pop()'' method when removing an Array
elements. For example:
oName = new Array(''Lucas'',''Brasilino'',''Silva'');
oName.remove(''Brasilino'');
oName.toString(); // puts out ''Lucas,Silva''
Any fancy function to me to add this as a ''remove()'' method ??
Thanks a lot in advance.
Bests regards
Lucas Brasilino
You can use the Array.splice() method.
The splice method takes as arguments an index which you want to start
removing elements and the number of elements to remove. For example in
your case:
var arrNames = new Array("Lucas", "Brasilino", "Silva");
arrNames.splice(1, 1); //start at index 1, remove 1 element.Probabely .splice() is the best choice.
Alternatively you can use "delete" keyword:
delete arrNames[1]
But then indexes in array wil be broken (0, and then 2, without 1)
and it would be possible to list the aray only using for(... in
....){...}
sc********@gmail.com wrote:Alternatively you can use "delete" keyword:
delete arrNames[1]
But then indexes in array wil be broken (0, and then 2, without 1)Indexes will not be "broken" - they keep going from 0 to the existing
array length, but the array will get a non-instantiated (undefined)
member inside.
What OP is really looking for is not an Array but Vector data type but
JavaScript doesn''t have such data type (though it can be emulated by
different means).
To stay withing the array mechanics slice/splice methods would be
indeed the best alternative.
这篇关于Array对象中是否有'remove()'方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!