热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

AS3-保持稀疏阵列稀疏-AS3-Keepingasparsearraysparse

ImworkingwithanarrayinAS3,whichissparsebydefault.Imakeanarrayandaddavaluetoit

I'm working with an array in AS3, which is sparse by default. I make an array and add a value to it at a given position. I nullify it's contents at that index. It retains that index value, but nullifies the contents. The issue is that the length still traces the same. Is there a way to actually remove that index without modifying any of the other indexes?

我正在使用AS3中的数组,默认情况下它是稀疏的。我创建一个数组并在给定位置添加一个值。我在该索引处使其内容无效。它保留该索引值,但使内容无效。问题是长度仍然跟踪相同。有没有办法在不修改任何其他索引的情况下实际删除该索引?

ex: 
array:Array = new Array();
array[ 7 ] = new Array();
array[ 16 ] = new Array();
array[ 16 ] = null;

Edit: I want the array the array to stay as small as possible, so that in the example above the array would trace as length 7.

编辑:我希望数组中的数组尽可能小,以便在上面的示例中,数组将跟踪长度为7。

2 个解决方案

#1


use the delete operator ... still, length will remain 8 ... setting the value for key 7 to null still means, there is a value for key 7, since Array may contain any values, including null. if you really use sparse arrays, then consider using flash.utils::Dictionary ... if key order matters, then look into flash.utils::Proxy ... or make some data structure, that does not use array access, but has some getVal and setVal methods instead ...

使用删除操作符...仍然,长度将保持为8 ...将键7的值设置为null仍然意味着,键7有一个值,因为数组可能包含任何值,包括null。如果你真的使用稀疏数组,那么考虑使用flash.utils :: Dictionary ...如果关键顺序很重要,那么请查看flash.utils :: Proxy ...或者制作一些不使用数组访问的数据结构,但是有一些getVal和setVal方法代替......

greetz

back2dos

#2


Try this

array.splice(7,1)

splice()


推荐阅读
author-avatar
小小鸟_--旺旺
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有