我有两个数组:
var valueArr:Array = [50,46,64,85,98,63,46,38,51,24,37,58,48,14,28];
var keyArr:Array = [5,6,7,8,9,10,11,12,13,14];
- keyArr:valueArr 的容器键
我想通过 keyArr 数组的键删除 valueArr 数组的值:
var resultArr:Array = [50,46,64,85,98];
我有两个数组:
var valueArr:Array = [50,46,64,85,98,63,46,38,51,24,37,58,48,14,28];
var keyArr:Array = [5,6,7,8,9,10,11,12,13,14];
我想通过 keyArr 数组的键删除 valueArr 数组的值:
var resultArr:Array = [50,46,64,85,98];
你可以这样做:
var valueArr:Array = [50,46,64,85,98,63,46,38,51,24,37,58,48,14,28];
var keyArr:Array = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14];
trace("valueArr",valueArr);//valueArr 50,46,64,85,98,63,46,38,51,24,37,58,48,14,28
trace("keyArr", keyArr);//keyArr 5,6,7,8,9,10,11,12,13,14
var i:int;
for (i = keyArr.length; --i >= 0; )
{
if (keyArr[i] < valueArr.length)
{
trace(valueArr.splice(keyArr[i], 1));
/*returned by above line
28
14
48
58
37
24
51
38
46
63
*/
}
}
trace("valueArr",valueArr);//valueArr 50,46,64,85,98
trace("keyArr",keyArr);//keyArr 5,6,7,8,9,10,11,12,13,14
问候