You are on page 1of 3

� ǽ�ũ��Ʈ 3.0������ Array Ŭ������ ��ο� � ҵ���� � � �Ǿ�4ϴ�..

� ���� �ְ� � �� ����ϴ��� � ƺ����� ����..

=========================================================================

every(callback:Function, thisObject:* = null):Boolean


�� �迭 ���� ��� ��Ҹ� �˻��մϴ�. �ϳ��� v�ǰ� ���� �ʴ ‫ �ٸ‬false��, ��� �´‫�ٸ‬
true�� ��ȯ�մϴ�.

<��뿹>
var tmpArr:Array = ["test1", "test2", 3];
trace(tmpArr.every(isNumeric)); //��� Number�� �ƴ Ƿ� false�� ��ȯ

function isNumeric(item:*, index:int, arr:Array):Boolean {


return (item is Number);
}

** ���� ���� ���ó�� �迭�� 0�� ��Һ��� ��ʴ�� ���鼭 false�� ���8� break�� �ɴ� �..

=========================================================================

forEach(callback:Function, thisObject:* = null):void


�� �迭; for��8�� ������ � � �� 4ϴ�.

<��뿹>
var tmpArr:Array = [
{Name:"ȫ�浿", Age:35},
{Name:"��ö��", Age:30},
{Name:"�̿���", Age:26},
{Name:"��� �", Age:30}
];
tmpArr.forEach(traceResult);

function traceResult(item:*, index:int, arr:Array):void {


trace("Name : ", item.Name, ", Age", item.Age);
}

//trace() ��
Name : ȫ�浿 , Age 35
Name : ��ö�� , Age 30
Name : �̿��� , Age 26
Name : ��� � , Age 30

=========================================================================

filter(callback:Function, thisObject:* = null):Array


�� v�ǿ� �´� ���‫� ;�ڵ‬ɷ��� �迭�� ��ȯ�մϴ�.

<��뿹>
var tmpArr:Array = [
{Name:"ȫ�浿", Age:35},
{Name:"��ö��", Age:30},
{Name:"�̿���", Age:26},
{Name:"��� �", Age:30}
];
var resultArr:Array = tmpArr.filter(getSameAge);
resultArr.forEach(traceResult); //��; ��� '�� '���� ������ forEach()�� ���

function getSameAge(item:*, index:int, arr:Array):Boolean {


return (item.Age == 30);
}

function traceResult(item:*, index:int, arr:Array):void {


trace("Name : ", item.Name, ", Age", item.Age);
}

//trace() ��
Name : ��ö�� , Age 30
Name : ��� � , Age 30

=========================================================================

indexOf(searchElement:*, fromIndex:int = 0):int


�� �迭���� searchElement�� ��: ����� index ��; �����մϴ�. (����: �� -> ��)

<��뿹>

var tmpArr:Array = ["�ָ�", "����", "����", "��"];


var index:int;

index = tmpArr.indexOf("����");
trace(index); //2

tmpArr.push("�ָ�"); //�ָ� � �

index = tmpArr.indexOf("�ָ�", 1); //�ι�° ��Һ��� �‫ ;�ָ� �ڷ‬ã=


trace(index); //4

=========================================================================

lastIndexOf(searchElement:*, fromIndex:int = 0x7fffffff):int


�� �迭���� searchElement�� ��: ����� index ��; �����մϴ�. (����: �� -> ��)

<��뿹>

var tmpArr:Array = ["�ָ�", "����", "����", "��"];


var index:int;

index = tmpArr.lastIndexOf("����");
trace(index); //2

tmpArr.push("�ָ�"); //�ָ� � �

index = tmpArr.lastIndexOf("�ָ�", 1); //�ι�° ��Һ��� ��8�� �ָ�; ã=


trace(index); //0

=========================================================================

map(callback:Function, thisObject:* = null):Array


�� �迭; for��8�� ���鼭 �‫ڵ‬带 ����ϴ� � � ���4ϴ�.

<��뿹>
var tmpArr:Array = new Array("hong", "kim", "lee");

var resultArr:Array = tmpArr.map(toUpper);


trace(resultArr); //HONG,KIM,LEE

function toUpper(item:*, index:int, arr:Array):String {


return String(item).toUpperCase();
}

=========================================================================

some(callback:Function, thisObject:* = null):Boolean


�� �迭 ���� ��� ��Ҹ� �˻��մϴ�. �ϳ��� v�ǰ� �´‫ �ٸ‬true��, ��� ���� �ʴ ‫ �ٸ‬false��
��ȯ�մϴ�.

<����>
var tmpArr:Array = new Array();
tmpArr[0] = "�ָ�";
tmpArr[1] = "����";
tmpArr[3] = "��";
var resultBoolean:Boolean = tmpArr.some(isUndefined);
trace(resultBoolean); //true

function isUndefined(item:*, index:int, arr:Array):Boolean {


return (item == undefined);
}

** every()�� ��� ��; ��� true�� ��ȯ���� some(): �ϳ��� ��; ��� true�� ��ȯ�մϴ�..

=========================================================================

�̻�� ϴ�..�� ���� � ҵ��: ��κ� ��x�� ����ϴ� �͵��̴� �� �ƽǰſ���..

������ ��� � �‫�ڱ‬s�4ϴ�..���� v���Ͻñ�^^