jQuery.map( array, callback ) Returns: Array
(version added: 1.0)
: 설명 : 배열 또는 개체의 모든 항목을 새 항목 배열로 변환합니다.
array
Type: Array
The Array to translate.
callback
Type: Function( Object elementOfArray, Integer indexInArray ) => Object
jQuery.map( object, callback ) Returns: Array
(version added: 1.6)
object
Type: Object
The Object to translate.
callback
Type: Function( Object propertyOfObject, String key ) => Object
* 예제 1
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery.map demo</title>
<style>
div {
color: blue;
}
p {
color: green;
margin: 0;
}
span {
color: red;
}
</style>
<script src="https://code.jquery.com/jquery-3.5.0.js"></script>
</head>
<body>
<div></div>
<p></p>
<span></span>
<script>
var arr = [ "a", "b", "c", "d", "e" ];
$( "div" ).text( arr.join( ", " ) );
arr = jQuery.map( arr, function( n, i ) {
return ( n.toUpperCase() + i );
});
$( "p" ).text( arr.join( ", " ) );
arr = jQuery.map( arr, function( a ) {
return a + a;
});
$( "span" ).text( arr.join( ", " ) );
</script>
</body>
</html>
$.map( [ 0, 1, 2 ], function( n ) {
return n + 4;
});
=> [4, 5, 6]
$.map( [ 0, 1, 2 ], function( n ) {
return n > 0 ? n + 1 : null;
});
=> [ 2, 3 ]
$.map( [ 0, 1, 2 ], function( n ) {
return [ n, n + 1 ];
});
=> [ 0, 1, 1, 2, 2, 3 ]
var dimensions = { width: 10, height: 15, length: 20 };
dimensions = $.map( dimensions, function( value, index ) {
return value * 2;
});
=> [ 20, 30, 40 ]
var dimensions = { width: 10, height: 15, length: 20 };
var keys = $.map( dimensions, function( value, key ) {
return key;
});
=> [ "width", "height", "length" ]
$.map( [ 0, 1, 2, 3 ], function( a ) {
return a * a;
});
=> [ 0, 1, 4, 9 ]
$.map( [ 0, 1, 52, 97 ], function( a ) {
return (a > 50 ? a - 45 : null);
});
=> [ 7, 52 ]
var array = [ 0, 1, 52, 97 ];
array = $.map( array, function( a, index ) {
return [ a - 45, index ];
});
=> [ -45, 0, -44, 1, 7, 2, 52, 3]
[ 출처 : api.jquery.com]
Jquery Form Serialize Disabled 컨트롤 넘기는 방법 (0) | 2021.03.24 |
---|---|
[JQuery] input 객체 - readonly, disabled 처리 (0) | 2021.03.24 |
jQuery.merge(first, second) Returns:Array (0) | 2021.02.09 |
.attr() (0) | 2021.02.03 |
.children() (0) | 2021.02.03 |
댓글 영역