¾È±Ô °øºÎ¹æ

Javascript & JQuery & CSS > jQuery ¹è¿­ inArray() - ¹è¿­°Ë»ö ¿¹Á¦

µî·ÏÀÏ : 2017-07-04 19:38 Á¶È¸¼ö : 53,855

1. inArray() °³¿ä : ¹è¿­ ³»ÀÇ °ªÀ» ã¾Æ¼­ À妽º¸¦ ¹ÝȯÇÕ´Ï´Ù.(¿ä¼Ò°¡ ¾øÀ» °æ¿ì -1À» ¹Ýȯ).
 
	jQuery.inArray( value, array [, fromIndex] )
	value ãÀ» value.
	array ´ë»ó ¹è¿­
	fromIndex °Ë»öÀÌ ½ÃÀÛµÉ ¹è¿­ÀÇ À妽º. ±âº»°ªÀº 0ÀÌ°í ¹è¿­ Àüü¸¦ °Ë»öÇÕ´Ï´Ù.



$.inArray() ÇÔ¼ö´Â JavaScriptÀÇ ±âº» ÇÔ¼öÀÎ .indexOf() ÇÔ¼ö¿Í À¯»çÇÕ´Ï´Ù. ¸¸ÀÏ ¹è¿­ ³»¿¡ ù¹ø° ¿ä¼Ò°¡ value ÀÎÀÚ¿Í ÀÏÄ¡ÇÑ´Ù¸é $.inArray() ÇÔ¼ö´Â 0À» ¸®ÅÏÇÕ´Ï´Ù.
¿¹Á¦
		<!DOCTYPE html>
		<html>
		<head>
		  <style>
		  div { color:blue; }
		  span { color:red; }
		</style>
		  <script src="http://code.jquery.com/jquery-latest.js"></script>
		</head>
		<body>
		  
		<div>"John" found at <span></span></div>
		<div>4 found at <span></span></div>
		<div>"Karl" not found, so <span></span></div>
		<div>"Pete" is in the array, but not at or after index 2, so <span></span></div>
		<script>var arr = [ 4, "Pete", 8, "John" ];
		var $spans = $("span");
		$spans.eq(0).text(jQuery.inArray("John", arr));
		$spans.eq(1).text(jQuery.inArray(4, arr));
		$spans.eq(2).text(jQuery.inArray("Karl", arr));
		$spans.eq(3).text(jQuery.inArray("Pete", arr, 2));
		</script>

		</body>
		</html>



¾Æ·¡´Â °á°ú°ªÀÔ´Ï´Ù.
 
"John" found at 3
4 found at 0
"Karl" not found, so -1
"Pete" is in the array, but not at or after index 2, so -1
	
¾Æ·¡¿Í °°Àº ÇüÅ·Π¹è¿­À» °Ë»öÇÏ°Ô µË´Ï´Ù.

	jQuery.inArray("John", arr)
	jQuery.inArray(4, arr)
	jQuery.inArray("Pete", arr, 2)

	¸Ç ¸¶Áö¸· ÀÎÀÚ 2¿¡ ÁÖ¸ñÇϼ¼¿ä. À妽º ±âÁØ 2º¸´Ù Å« ¹è¿­ ¿ä¼ÒºÎÅÍ °Ë»öÇÏ´Â °ÍÀÔ´Ï´Ù.

	indexOf() °°ÀÌ »ç¿ëÇÏ´Â °Å´Ï±î ±×¸® ¾î·Á¿î °³³äÀº ¾Æ´Ï³×¿ä. jQuery ±¸¹® Áß¿¡ ¹è¿­ ¿ä¼Ò¸¦ ãÀ» ¶§ »ç¿ëÇØ º¸¾Æ¿ä~
¡Ø Ȥ½Ã µµ¿òÀÌ µÇ¼Ì´Ù¸é ´ñ±Û¿¡ ÇѸ¶µð ³²°ÜÁÖ¼¼¿ä!
ÀÛ¼ºÀÚ   ºñ¹Ð¹øÈ£
ÀÚµ¿±Û ¹æÁö     (ÀÚµ¿±Û ¹æÁö ±â´ÉÀÔ´Ï´Ù.)
³»¿ë   ´ñ±Û´Þ±â 
À̸ÞÀÏ ¹®ÀÇ : cak0280@nate.com  
Copyright 2000 By ENTERSOFT.KR All Rights Reserved.