actionscript 3 - AS3/Flash: Array convertion (two questions) -
1) have array:
var n:array = ["james", "jane", "jamel"...];
and need transfor this:
var nt:array = [{label:"james"}, {label:"jane"}, {label:"jamel"}...];
2) possible sort , remove duplicated names in:
var n:array = [{label:"james"}, {label:"jane"}, {label:"jamel"}, {label:"jane"},...];
thanks in advance.
var initialarray: array = ["james", "jane", "jamel", "jane", "jamel"]; var resultingarray: array = []; //sorting array initialarray.sort(); //removing duplicates var i: int = 0; while (i < initialarray.length) { while (i < initialarray.length + 1 && initialarray[i] == initialarray[i + 1]) { initialarray.splice(i, 1); } i++; } //converting each(var elem: object in initialarray) { var currentobject: object = new object(); currentobject.label = elem; resultingarray.push(currentobject); }
you can work resultingarray
you may want use original or while loop, possibly increase speed of piece of code.
Comments
Post a Comment