Utilities/API/jQuery - Sample Code
jQuery.map(array, callback)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script src="/jquery/js/jquery.js"></script>
<script>
$(document).ready(function(){
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 (n, i) {
var x = n + n;
if (i==1) return null;
if (i==3) return [x, x, x];
return x;
});
$("span").text(arr.join(", "));
});
</script>
<style>
div { color:blue; }
p { color:green; margin:0; }
span { color:red; }
</style>
</head>
<body>
<div></div>
<p></p>
<span></span>
</body>
</html>
[実行結果]