{"id":4797,"date":"2013-11-19T07:18:00","date_gmt":"2013-11-18T22:18:00","guid":{"rendered":"http:\/\/www.webcyou.com\/?p=4797"},"modified":"2013-11-19T07:18:00","modified_gmt":"2013-11-18T22:18:00","slug":"%e3%80%90js%e3%80%91%e3%80%90%e4%bf%9d%e5%ad%98%e7%89%88%e3%80%91underscore-js-%e3%81%ae%e4%bd%bf%e7%94%a8%e6%96%b9%e6%b3%95-%e3%81%be%e3%81%a8%e3%82%81-collection-functions","status":"publish","type":"post","link":"https:\/\/www.webcyou.com\/?p=4797","title":{"rendered":"\u3010JS\u3011\u3010\u4fdd\u5b58\u7248\u3011underscore.js \u306e\u4f7f\u7528\u65b9\u6cd5 \u307e\u3068\u3081 Collection Functions"},"content":{"rendered":"<h4 id=\"collections\"><strong>underscore.js<\/strong><\/h4>\n<p>\u3069\u3082\u3002<\/p>\n<p>\u4e16\u9593\u3067\u306f\u3001\u306a\u3093\u3061\u3083\u3089js\u304c\u591a\u304f\u6ea2\u308c\u3066\u3044\u3066\u3001\u4f55\u304c\u306a\u3093\u3084\u3089\u3067\u5927\u5909\u3067\u3059\u306d\u3002<\/p>\n<p>\u3067\u3082\u3001\u305d\u3093\u306a\u306a\u3093\u3061\u3083\u3089js\u304c\u7686\u3055\u3093\u597d\u304d\u306a\u306e\u304b\u3082\u77e5\u308c\u307e\u305b\u3093\u306d\u3002<\/p>\n<p>\u3068\u3001\u305d\u3093\u306a\u611f\u3058\u3067\u3001\u4eca\u56de\u306f\u767b\u5834\u3057\u3066\u3061\u3087\u3063\u3068\u7d4c\u3061\u307e\u3059\u304c\u3001\u914d\u5217\u64cd\u4f5c\u306b\u4fbf\u5229\u306a<strong> underscore.js\u00a0<\/strong>\u306b\u3064\u3044\u3066\u66f8\u3044\u3066\u898b\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p><strong>\u6b63\u5f0f\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8<\/strong><\/p>\n<p><strong>underscore.js<\/strong><\/p>\n<p><a href=\"http:\/\/underscorejs.org\" target=\"_blank\">http:\/\/underscorejs.org<\/a><\/p>\n<p><a href=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/fb300de5e74298cbdddd51331f9609ab.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/fb300de5e74298cbdddd51331f9609ab.png\" alt=\"\" title=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2013-11-19 2.40.31\" width=\"444\" height=\"110\" class=\"alignnone size-full wp-image-4798\" srcset=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/fb300de5e74298cbdddd51331f9609ab.png 444w, https:\/\/www.webcyou.com\/wp-content\/uploads\/fb300de5e74298cbdddd51331f9609ab-300x74.png 300w\" sizes=\"auto, (max-width: 444px) 100vw, 444px\" \/><\/a><\/p>\n<p>\u3053\u306e\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306b\u6cbf\u3063\u3066\u3001<\/p>\n<p>\u30e1\u30bd\u30c3\u30c9\u306e\u7528\u9014\u3092\u4e00\u8a00\u3002<\/p>\n<p>\u6b63\u5f0f\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u3002<\/p>\n<p>\u4f7f\u7528\u4f8b\u3002<\/p>\n<p>\u3092\u66f8\u3044\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\uff01<\/p>\n<h4>Collection Functions (Arrays or Objects)<\/h4>\n<h5 id=\"each\"><strong>each<\/strong><\/h5>\n<p>_.each(list, iterator, [context])<\/p>\n<p>\u914d\u5217\u306e\u6570\u306e\u51e6\u7406\u3092\u5b9f\u884c\u3002<\/p>\n<pre>_.each([1, 2, 3], alert);\r\n=&gt; alerts each number in turn...\r\n_.each({one: 1, two: 2, three: 3}, alert);\r\n=&gt; alerts each number value in turn...<\/pre>\n<p><strong>example<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">(function() {\r\n _.each(&#x5B;3, 4, 5, 6], function(num) {\r\n console.log(num * 2);\r\n });\r\n})();<\/pre>\n<p><a href=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/dbdf5f111aaab1725bee5c52afe44833.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/dbdf5f111aaab1725bee5c52afe44833.png\" alt=\"\" title=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2013-11-19 2.58.25\" width=\"59\" height=\"71\" class=\"alignnone size-full wp-image-4800\" \/><\/a><\/p>\n<h5 id=\"map\"><strong>map\u00a0<\/strong><\/h5>\n<p>_.map(list, iterator, [context])<\/p>\n<p>\u914d\u5217\u306e\u6570\u51e6\u7406\u3057\u3001\u914d\u5217\u306b\u683c\u7d0d<\/p>\n<pre>_.map([1, 2, 3], function(num){ return num * 3; });\r\n=&gt; [3, 6, 9]\r\n_.map({one: 1, two: 2, three: 3}, function(num, key){ return num * 3; });\r\n=&gt; [3, 6, 9]<\/pre>\n<p><strong>example<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">(function() {\r\n var x = _.map(&#x5B;3, 4, 5, 6], function(num) {\r\n return num * 2;\r\n });\r\n console.log(x);\r\n})();<\/pre>\n<p><a href=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/00f091d9d5b3ce3641786e6d0b2f04af.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/00f091d9d5b3ce3641786e6d0b2f04af.png\" alt=\"\" title=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2013-11-19 3.06.08\" width=\"129\" height=\"29\" class=\"alignnone size-full wp-image-4801\" \/><\/a><\/p>\n<h5 id=\"reduce\"><strong>reduce\u00a0<\/strong><\/h5>\n<p>_.reduce(list, iterator, memo, [context])<\/p>\n<p>\u914d\u5217\u3092\uff11\u3064\u306e\u5024\u306b\u96c6\u7d04\u3059\u308b\u3002memo\u304c\u521d\u671f\u5024\u3002<\/p>\n<pre>var sum = _.reduce([1, 2, 3], function(memo, num){ return memo + num; }, 0);\r\n=&gt; 6<\/pre>\n<p><strong>example<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">(function() {\r\n var x = _.reduce(&#x5B;3, 4, 5, 6], function(memo, num) {\r\n return memo + num;\r\n }, 0);\r\n console.log(x);\r\n})();<\/pre>\n<p><a href=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/7999632f13614b957054bb4efd0748ce.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/7999632f13614b957054bb4efd0748ce.png\" alt=\"\" title=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2013-11-19 3.16.53\" width=\"63\" height=\"45\" class=\"alignnone size-full wp-image-4802\" \/><\/a><\/p>\n<p>\u4e0a\u8a18\u306e\u5834\u5408\u30010\u304c\u521d\u671f\u5024\u3002<\/p>\n<h5 id=\"reduceRight\"><strong>reduceRight\u00a0<\/strong><\/h5>\n<p>_.reduceRight(list, iterator, memo, [context])<\/p>\n<p><strong>reduce\u3092\u53f3\u304b\u3089\u51e6\u7406<\/strong><\/p>\n<pre>var list = [[0, 1], [2, 3], [4, 5]];\r\nvar flat = _.reduceRight(list, function(a, b) { return a.concat(b); }, []);\r\n=&gt; [4, 5, 2, 3, 0, 1]<\/pre>\n<p><strong>example<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">(function() {\r\n var list = &#x5B;&#x5B;2, 3], &#x5B;4, 5], &#x5B;6, 7]];\r\n var x = _.reduceRight(list, function(a, b) {\r\n return a.concat(b);\r\n }, &#x5B;]);\r\n console.log(x);\r\n})();<\/pre>\n<p><a href=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/a30a1c54513016862aa3944e42122246.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/a30a1c54513016862aa3944e42122246.png\" alt=\"\" title=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2013-11-19 3.23.58\" width=\"153\" height=\"45\" class=\"alignnone size-full wp-image-4803\" srcset=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/a30a1c54513016862aa3944e42122246.png 153w, https:\/\/www.webcyou.com\/wp-content\/uploads\/a30a1c54513016862aa3944e42122246-150x45.png 150w\" sizes=\"auto, (max-width: 153px) 100vw, 153px\" \/><\/a><\/p>\n<h5 id=\"find\"><strong>find<\/strong><\/h5>\n<p>_.find(list, iterator, [context])<\/p>\n<p>\u6761\u4ef6\u5224\u5b9a\u3067\u691c\u7d22<\/p>\n<pre>var even = _.find([1, 2, 3, 4, 5, 6], function(num){ return num % 2 == 0; });\r\n=&gt; 2<\/pre>\n<p><strong>example<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">(function() {\r\n var a = &#x5B;4, 6, 10, 65, 32];\r\n var x = _.find(a, function(num) {\r\n return num &gt; 7;\r\n });\r\n console.log(x);\r\n})();<\/pre>\n<p><a href=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/eaadbffed7ef931f46e8ecedd3401cd2.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/eaadbffed7ef931f46e8ecedd3401cd2.png\" alt=\"\" title=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2013-11-19 3.35.08\" width=\"65\" height=\"40\" class=\"alignnone size-full wp-image-4805\" \/><\/a><\/p>\n<h5 id=\"filter\"><strong>filter<\/strong><\/h5>\n<p><strong><\/strong><code>_.filter(list, iterator, [context])<\/code><\/p>\n<p>\u6761\u4ef6\u3092\u6e80\u305f\u3059\u5024\u3092\u8fd4\u3059<\/p>\n<pre>var evens = _.filter([1, 2, 3, 4, 5, 6], function(num){ return num % 2 == 0; });\r\n=&gt; [2, 4, 6]<\/pre>\n<p><strong>example<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">(function() {\r\n var a = &#x5B;4, 6, 10, 65, 32];\r\n var x = _.filter(a, function(num) {\r\n return num &gt; 7;\r\n });\r\n console.log(x);\r\n})();<\/pre>\n<p><a href=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/465f546b522c05b62378d466122c9968.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/465f546b522c05b62378d466122c9968.png\" alt=\"\" title=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2013-11-19 3.38.53\" width=\"103\" height=\"31\" class=\"alignnone size-full wp-image-4806\" \/><\/a><\/p>\n<h5 id=\"where\"><strong>where<\/strong><\/h5>\n<p>_.where(list, properties)<\/p>\n<p>\u8a72\u5f53\u3059\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u5168\u3066\u8fd4\u3059<\/p>\n<pre>_.where(listOfPlays, {author: \"Shakespeare\", year: 1611});\r\n=&gt; [{title: \"Cymbeline\", author: \"Shakespeare\", year: 1611},\r\n    {title: \"The Tempest\", author: \"Shakespeare\", year: 1611}]<\/pre>\n<p><strong>example<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">(function() {\r\n var listOfPlays = &#x5B;\r\n {\r\n   title: \"Cymbeline\",\r\n   author: \"Shakespeare\", \r\n   year: 1611\r\n },\r\n {\r\n   title: \"The Tempest\",\r\n   author: \"Shakespeare\", \r\n   year: 1611\r\n },\r\n {\r\n   title: \"web\u5e33\",\r\n   author: \"me\", \r\n   year: 1978\r\n }\r\n ];\r\n var x = _.where(listOfPlays, {author: \"me\", year: 1978});\r\n console.log(x);\r\n})();<\/pre>\n<p><a href=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/5aefed2e26445d0565949d67d97c4be1.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/5aefed2e26445d0565949d67d97c4be1.png\" alt=\"\" title=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2013-11-19 3.54.58\" width=\"176\" height=\"119\" class=\"alignnone size-full wp-image-4807\" \/><\/a><\/p>\n<h5 id=\"findWhere\"><strong>findWhere<\/strong><\/h5>\n<p>_.findWhere(list, properties)<\/p>\n<p>\u8a72\u5f53\u3059\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u63a2\u3059<\/p>\n<pre>_.findWhere(publicServicePulitzers, {newsroom: \"The New York Times\"});\r\n=&gt; {year: 1918, newsroom: \"The New York Times\",\r\n  reason: \"For its public service in publishing in full so many official reports,\r\n  documents and speeches by European statesmen relating to the progress and\r\n  conduct of the war.\"}<\/pre>\n<p><strong>example<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">(function() { \r\n var listOfPlays = &#x5B;\r\n {\r\n title: \"Cymbeline\",\r\n author: \"Shakespeare\", \r\n year: 1611\r\n },\r\n {\r\n title: \"The Tempest\",\r\n author: \"Shakespeare\", \r\n year: 1611\r\n },\r\n {\r\n title: \"web\u5e33\",\r\n author: \"me\", \r\n year: 1978\r\n }\r\n ];\r\n var x = _.findWhere(listOfPlays, {author: \"Shakespeare\"});\r\n console.log(x);\r\n})();<\/pre>\n<p><a href=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/d19accf3482f692cdef113f2d9651e7c.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/d19accf3482f692cdef113f2d9651e7c.png\" alt=\"\" title=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2013-11-19 3.59.01\" width=\"451\" height=\"33\" class=\"alignnone size-full wp-image-4808\" srcset=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/d19accf3482f692cdef113f2d9651e7c.png 451w, https:\/\/www.webcyou.com\/wp-content\/uploads\/d19accf3482f692cdef113f2d9651e7c-300x21.png 300w\" sizes=\"auto, (max-width: 451px) 100vw, 451px\" \/><\/a><\/p>\n<h5 id=\"reject\"><strong>reject<\/strong><\/h5>\n<p>_.reject(list, iterator, [context])<\/p>\n<p>\u30ea\u30b9\u30c8\u306e\u8981\u7d20\u306e\u4e2d\u304b\u3089\u3001\u771f\u5024\u30c6\u30b9\u30c8\u3092\u901a\u904e\u3057\u306a\u304b\u3063\u305f\u3082\u306e\u3092\u8fd4\u3059\u3002<\/p>\n<pre>var odds = _.reject([1, 2, 3, 4, 5, 6], function(num){ return num % 2 == 0; });\r\n=&gt; [1, 3, 5]<\/pre>\n<p><strong>example<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">(function() {\r\n var a = &#x5B;5, 8, 12, 13, 15, 26]\r\n var x = _.reject(a, function(num) { \r\n return num % 2 == 0; \r\n });\r\n console.log(x);\r\n})();<\/pre>\n<p><a href=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/6a9e5b7d087663d067d3f4ed6ce91a66.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/6a9e5b7d087663d067d3f4ed6ce91a66.png\" alt=\"\" title=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2013-11-19 4.10.45\" width=\"119\" height=\"39\" class=\"alignnone size-full wp-image-4809\" \/><\/a><\/p>\n<h5 id=\"every\"><strong>every<\/strong><\/h5>\n<p>_.every(list, [iterator], [context])\u00a0Alias:\u00a0<strong>all<\/strong><\/p>\n<p>list\u00a0\u306e\u5024\u3059\u3079\u3066\u304c\u00a0iterator\u00a0\u771f\u5024\u30c6\u30b9\u30c8\u3092\u30d1\u30b9\u3057\u305f\u3089\u00a0<em>true<\/em>\u00a0\u3092\u8fd4\u3057\u307e\u3059\u3002<\/p>\n<pre>_.every([true, 1, null, 'yes'], _.identity);\r\n=&gt; false<\/pre>\n<p><strong>example<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">(function() {\r\nvar x = _.every(&#x5B;'hoge', 'no', 'null', 'yes'], _.identity);\r\n console.log(x);\r\n})();<\/pre>\n<p><a href=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/1715ba87cc42e7e09c2ac2507cb341ae.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/1715ba87cc42e7e09c2ac2507cb341ae.png\" alt=\"\" title=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2013-11-19 4.21.16\" width=\"67\" height=\"36\" class=\"alignnone size-full wp-image-4810\" \/><\/a><\/p>\n<h5><strong>some<\/strong><\/h5>\n<p>_.some(list, [iterator], [context])<\/p>\n<p>list\u00a0\u306e\u5024\u306e\u3069\u308c\u304b\u304c\u00a0iterator\u00a0\u771f\u5024\u30c6\u30b9\u30c8\u3092\u30d1\u30b9\u3057\u305f\u3089\u00a0<em>true<\/em>\u00a0\u3092\u8fd4\u3057\u307e\u3059\u3002\/<\/p>\n<p><pre>_.some([null, 0, 'yes', false]);\r\n=&gt; true<\/pre>\n<p><strong>example<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">(function() {\r\nvar x = _.some(&#x5B;null, false, null, 0]);\r\n console.log(x);\r\n})();<\/pre>\n<p><a href=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/b1bd9bf0c6bb51543b159b72fd7fbbdd.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/b1bd9bf0c6bb51543b159b72fd7fbbdd.png\" alt=\"\" title=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2013-11-19 4.26.01\" width=\"65\" height=\"41\" class=\"alignnone size-full wp-image-4811\" \/><\/a><\/p>\n<h5 id=\"contains\"><strong>contains<\/strong><\/h5>\n<p>_.contains(list, value)<\/p>\n<p>list\u00a0\u306e\u5024\u306bvalue\u304c\u307f\u3064\u304b\u308c\u3070\u00a0<em>true<\/em>\u00a0\u3092\u8fd4\u3057\u307e\u3059\u3002<\/p>\n<pre>_.contains([1, 2, 3], 3);\r\n=&gt; true<\/pre>\n<p><strong>example<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">(function() {\r\n var a = &#x5B;5, 8, 12, 13, 15, 26]\r\n var x = _.contains(a, 26); \r\n console.log(x);\r\n})();<\/pre>\n<p><a href=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/502a23d9c132eb4ddf6232c2b9c93bc6.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/502a23d9c132eb4ddf6232c2b9c93bc6.png\" alt=\"\" title=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2013-11-19 4.28.50\" width=\"63\" height=\"34\" class=\"alignnone size-full wp-image-4812\" \/><\/a><\/p>\n<h5><strong>invoke<\/strong><\/h5>\n<p>_.invoke(list, methodName, [*arguments])<\/p>\n<p>\u00a0<\/p>\n<p>list\u306e\u4e2d\u306e\u305d\u308c\u305e\u308c\u306e\u5024\u306b\u5bfe\u3057\u3066\u00a0methodName\u00a0\u3067\u6307\u540d\u3055\u308c\u305f\u30e1\u30bd\u30c3\u30c9\u3092\u30b3\u30fc\u30eb\u3057\u307e\u3059\u3002<\/p>\n<pre>_.invoke([[5, 1, 7], [3, 2, 1]], 'sort');\r\n=&gt; [[1, 5, 7], [1, 2, 3]]<\/pre>\n<p><strong>example<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">(function() {\r\n var a = &#x5B;5, 8, 12, 13, 15, 26]\r\n var x = _.invoke(&#x5B;&#x5B;5, 2, 7, \"3943\"], &#x5B;'\u30c6\u30ad\u30b9\u30c8', 2, 1]], 'sort'); \r\n console.log(x);\r\n})();<\/pre>\n<p><a href=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/3086b194f5709d056032259b81decc75.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/3086b194f5709d056032259b81decc75.png\" alt=\"\" title=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2013-11-19 4.42.15\" width=\"134\" height=\"172\" class=\"alignnone size-full wp-image-4813\" \/><\/a><\/p>\n<h5 id=\"pluck\"><strong>pluck<\/strong><\/h5>\n<p>_.pluck(list, propertyName)<\/p>\n<p>map\u306e\u4fbf\u5229\u7248\u3002\u30d7\u30ed\u30d1\u30c6\u30a3\u5024\u306e\u30ea\u30b9\u30c8\u306e\u62bd\u51fa\u3002<\/p>\n<pre>var stooges = [{name: 'moe', age: 40}, {name: 'larry', age: 50}, {name: 'curly', age: 60}];<\/pre>\n<pre>_.pluck(stooges, 'name');\r\n=&gt; [\"moe\", \"larry\", \"curly\"]<\/pre>\n<p><strong>example<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">(function() {\r\n var person = &#x5B;\r\n { name: '\u308f\u305f\u3057', age: 20 }, \r\n { name: '\u3042\u306a\u305f', age: 22 },\r\n { name: '\u305d\u306a\u305f', age: 40 }\r\n ];\r\nvar x = _.pluck(person, 'name'); \r\n console.log(x);\r\n})();<\/pre>\n<p><a href=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/1e84a344673deb7cbdf0b20dec7e1cf2.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/1e84a344673deb7cbdf0b20dec7e1cf2.png\" alt=\"\" title=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2013-11-19 4.48.50\" width=\"231\" height=\"46\" class=\"alignnone size-full wp-image-4814\" \/><\/a><\/p>\n<p id=\"max\"><strong>max<\/strong><\/p>\n<p>_.max(list, [iterator], [context])<\/p>\n<p>list\u00a0\u306e\u4e2d\u306e\u6700\u5927\u5024\u3092\u8fd4\u3057\u307e\u3059\u3002<\/p>\n<pre>var stooges = [{name: 'moe', age: 40}, {name: 'larry', age: 50}, {name: 'curly', age: 60}];\r\n_.max(stooges, function(stooge){ return stooge.age; });\r\n=&gt; {name: 'curly', age: 60};<\/pre>\n<p><strong>example<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">(function() {\r\n var person = &#x5B;\r\n { name: '\u308f\u305f\u3057', age: 20 }, \r\n { name: '\u3042\u306a\u305f', age: 22 },\r\n { name: '\u305d\u306a\u305f', age: 40 }\r\n ];\r\n var x = _.max(person, function(stooge) { return stooge.age; });\r\n console.log(x);\r\n})();<\/pre>\n<p><a href=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/0d8fb1d70c2080e90b827f8bff16bd75.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/0d8fb1d70c2080e90b827f8bff16bd75.png\" alt=\"\" title=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2013-11-19 4.50.59\" width=\"258\" height=\"52\" class=\"alignnone size-full wp-image-4815\" \/><\/a><\/p>\n<p><h5>min<\/h5>\n<p>_.min(list, [iterator], [context])<\/p>\n<p>\u00a0<\/p>\n<p>list\u00a0\u306e\u4e2d\u306e\u6700\u5c0f\u5024\u3092\u8fd4\u3057\u307e\u3059\u3002<\/p>\n<pre>var numbers = [10, 5, 100, 2, 1000];\r\n_.min(numbers);\r\n=&gt; 2<\/pre>\n<p><strong>example<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">(function() {\r\n var person = &#x5B;\r\n { name: '\u308f\u305f\u3057', age: 20 }, \r\n { name: '\u3042\u306a\u305f', age: 22 },\r\n { name: '\u305d\u306a\u305f', age: 40 }\r\n ];\r\nvar x = _.min(person, function(stooge) { return stooge.age; });\r\n console.log(x);\r\n})();<\/pre>\n<p><a href=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/45b4b24371f7d753d0c77636195b2592.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/45b4b24371f7d753d0c77636195b2592.png\" alt=\"\" title=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2013-11-19 4.52.34\" width=\"269\" height=\"52\" class=\"alignnone size-full wp-image-4816\" \/><\/a><\/p>\n<h5 id=\"sortBy\"><strong>sortBy<\/strong><\/h5>\n<p>_.sortBy(list, iterator, [context])<\/p>\n<p>\u305d\u308c\u305e\u308c\u306e\u5024\u3092\u00a0iterator\u00a0\u306b\u901a\u3057\u305f\u7d50\u679c\u3067\u30e9\u30f3\u30af\u4ed8\u3051\u3057\u305f\u9806\u306b\u4e26\u3073\u66ff\u3048\u3089\u308c\u305flist\u00a0\u306e\u30b3\u30d4\u30fc\u3092\u8fd4\u3059\u3002<\/p>\n<pre>_.sortBy([1, 2, 3, 4, 5, 6], function(num){ return Math.sin(num); });\r\n=&gt; [5, 4, 6, 3, 1, 2]<\/pre>\n<p><strong>example<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">(function() {\r\n var a = &#x5B;1, 2, 3, 4, 5, 6];\r\n var x = _.sortBy(a, function(num) { return num * -1; });\r\n console.log(x);\r\n})();<\/pre>\n<p><a href=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/86b2e4505c6e5ed9ce663dc8116f058c.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/86b2e4505c6e5ed9ce663dc8116f058c.png\" alt=\"\" title=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2013-11-19 5.10.44\" width=\"145\" height=\"32\" class=\"alignnone size-full wp-image-4818\" \/><\/a><\/p>\n<h5 id=\"groupBy\"><strong>groupBy<\/strong><\/h5>\n<p>_.groupBy(list, iterator, [context])<\/p>\n<p>\u305d\u308c\u305e\u308c\u306e\u5024\u3092\u00a0iterator\u306b\u901a\u3057\u305f\u7d50\u679c\u30b0\u30eb\u30fc\u30d7\u5316\u3057\u305f\u7d44\u306b\u5206\u3051\u307e\u3059\u3002 \u00a0iterator\u00a0\u304c\u95a2\u6570\u3067\u306f\u306a\u304f\u6587\u5b57\u5217\u306a\u3089\u3001\u5024\u306e\u305d\u308c\u305e\u308c\u306b\u5bfe\u3059\u308b\u00a0iterator\u00a0\u3068\u540d\u4ed8\u3051\u3089\u308c\u305f\u30d7\u30ed\u30d1\u30c6\u30a3\u3067\u30b0\u30eb\u30fc\u30d7\u5316\u3057\u307e\u3059\u3002<\/p>\n<pre>_.groupBy([1.3, 2.1, 2.4], function(num){ return Math.floor(num); });\r\n=&gt; {1: [1.3], 2: [2.1, 2.4]}<\/pre>\n<pre>_.groupBy(['one', 'two', 'three'], 'length');\r\n=&gt; {3: [\"one\", \"two\"], 5: [\"three\"]}<\/pre>\n<p><strong>example<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">(function() {\r\n var a = &#x5B;3, 4, 6, 8, 13, 15];\r\n var x = _.groupBy(a, function(num){ \r\n return num % 3;\r\n });\r\n console.log(x);\r\n})();<\/pre>\n<p><a href=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/27bfd21e0a3b56e8a3392ff4973e9e0b.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/27bfd21e0a3b56e8a3392ff4973e9e0b.png\" alt=\"\" title=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2013-11-19 5.16.57\" width=\"158\" height=\"212\" class=\"alignnone size-full wp-image-4819\" \/><\/a><\/p>\n<h5 id=\"indexBy\"><strong>indexBy<\/strong><\/h5>\n<p>_.indexBy(list, iterator, [context])<\/p>\n<p>iterator\u306e\u30ad\u30fc\u306e\u5024\u3092\u5143\u306b\u7d50\u679c\u3092\u8fd4\u3057\u307e\u3059\u3002<\/p>\n<pre>var stooges = [{name: 'moe', age: 40}, {name: 'larry', age: 50}, {name: 'curly', age: 60}];\r\n_.indexBy(stooges, 'age');\r\n=&gt; {\r\n  \"40\": {name: 'moe', age: 40},\r\n  \"50\": {name: 'larry', age: 50},\r\n  \"60\": {name: 'curly', age: 60}\r\n}<\/pre>\n<p><strong>example<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">(function() {\r\n var person = &#x5B;\r\n {name: 'moe', age: 40}, \r\n {name: 'larry', age: 40}, \r\n {name: 'curly', age: 40}\r\n ];\r\nvar x = _.indexBy(person, 'age');\r\nconsole.log(x);\r\n})();<\/pre>\n<p><a href=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/fc35c14c1314f2d40276a7f9db2c179f.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/fc35c14c1314f2d40276a7f9db2c179f.png\" alt=\"\" title=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2013-11-19 5.29.29\" width=\"221\" height=\"125\" class=\"alignnone size-full wp-image-4820\" \/><\/a><\/p>\n<p><h5 id=\"countBy\"><strong>countBy<\/strong><\/h5>\n<p>_.countBy(list, iterator, [context])<\/p>\n<p>\u305d\u308c\u305e\u308c\u306e\u5024\u3092\u00a0iterator\u306b\u901a\u3057\u305f\u7d50\u679c\u30b0\u30eb\u30fc\u30d7\u5316\u3057\u305f\u7d44\u306b\u5206\u3051\u3001\u305d\u306e\u7d50\u679c\u306e\u6570\u3092\u8fd4\u3059\u3002<\/p>\n<pre>_.countBy([1, 2, 3, 4, 5], function(num) {\r\n  return num % 2 == 0 ? 'even': 'odd';\r\n});\r\n=&gt; {odd: 3, even: 2}<\/pre>\n<p><strong>example<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">(function() {\r\n var a = &#x5B;2, 3, 6, 8, 18, 21];\r\n var x = _.countBy(a, function(num) {\r\n return num % 3 == 0 ? '3\u306e\u500d\u6570' : '3\u306e\u500d\u6570\u4ee5\u5916';\r\n });\r\nconsole.log(x);\r\n})();<\/pre>\n<p><a href=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/4e137ca2e25d4f1a3281424d46766f99.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/4e137ca2e25d4f1a3281424d46766f99.png\" alt=\"\" title=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2013-11-19 6.08.39\" width=\"246\" height=\"33\" class=\"alignnone size-full wp-image-4822\" \/><\/a><\/p>\n<h5 id=\"shuffle\"><strong>shuffle<\/strong><\/h5>\n<p>_.shuffle(list)<\/p>\n<p>list\u00a0\u306e\u5024\u3092\u30b7\u30e3\u30c3\u30d5\u30eb\u3055\u308c\u305f\u30b3\u30d4\u30fc\u3092\u8fd4\u3057\u307e\u3059\u3002<\/p>\n<pre>_.shuffle([1, 2, 3, 4, 5, 6]);\r\n=&gt; [4, 1, 6, 3, 5, 2]<\/pre>\n<p><strong>example<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">(function() {\r\n var a = &#x5B;\"web\u5e33\", 3, 6, 8, \"\u725b\u4e3c\", 21];\r\n var x = _.shuffle(a);\r\n console.log(x);\r\n})();<\/pre>\n<p><a href=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/eb3356d186d9c6484932755effd53f38.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/eb3356d186d9c6484932755effd53f38.png\" alt=\"\" title=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2013-11-19 6.11.04\" width=\"221\" height=\"36\" class=\"alignnone size-full wp-image-4823\" \/><\/a><\/p>\n<h5 id=\"sample\"><strong>sample<\/strong><\/h5>\n<p><strong><\/strong><code>_.sample(list, [n])<\/p>\n<p>\u00a0<\/p>\n<p>list\u00a0\u306e\u5024\u3092\u30e9\u30f3\u30c0\u30e0\u306b\u6a19\u672c\u3068\u3057\u3066\u53d6\u5f97\u3057\u307e\u3059\u3002<\/p>\n<pre>_.sample([1, 2, 3, 4, 5, 6]);\r\n=&gt; 4\r\n\r\n_.sample([1, 2, 3, 4, 5, 6], 3);\r\n=&gt; [1, 6, 2]<\/pre>\n<p><strong>example<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">(function() {\r\n var a = &#x5B;\"web\u5e33\", 3, 6, 8, \"\u725b\u4e3c\", 21];\r\n var x = _.sample(a, 3);\r\n console.log(x);\r\n})();<\/pre>\n<p><a href=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/980b17f8e793ebcb4704e13a9f929b1d.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/980b17f8e793ebcb4704e13a9f929b1d.png\" alt=\"\" title=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2013-11-19 6.14.01\" width=\"188\" height=\"53\" class=\"alignnone size-full wp-image-4824\" \/><\/a><\/p>\n<h5 id=\"toArray\"><strong>toArray<\/strong><\/h5>\n<p>_.toArray(list)<\/p>\n<p>list\u3092Array\u306b\u5909\u63db\u3059\u308b\u3002<\/p>\n<pre>(function(){ return _.toArray(arguments).slice(1); })(1, 2, 3, 4);\r\n=&gt; [2, 3, 4]<\/pre>\n<p><strong>example<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">(function() {\r\n var x = (function() { \r\n return _.toArray(arguments); \r\n })(1,3,4,\"web\u5e33\");\r\n console.log(x);\r\n})();<\/pre>\n<p><a href=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/0f9e71900b329a6ed0cdf6a40cc877a7.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/0f9e71900b329a6ed0cdf6a40cc877a7.png\" alt=\"\" title=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2013-11-19 6.25.40\" width=\"167\" height=\"41\" class=\"alignnone size-full wp-image-4825\" \/><\/a><\/p>\n<h5 id=\"size\"><strong>size<\/strong><\/h5>\n<p>_.size(list)<\/p>\n<p>list\u306b\u542b\u307e\u308c\u3066\u3044\u308b\u8981\u7d20\u306e\u6570\u3092\u8fd4\u3059\u3002<\/p>\n<pre>_.size({one: 1, two: 2, three: 3});\r\n=&gt; 3<\/pre>\n<p><strong>example<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">(function() {\r\n var a = {\r\n one: 1, \r\n two: 2, \r\n three: 3,\r\n webcyou: \"https:\/\/www.webcyou.com\/\"\r\n }\r\n var x = _.size(a);\r\n console.log(x);\r\n})();<\/pre>\n<p><a href=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/ed444f4ae571c3c5e624b322db5d1710.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/ed444f4ae571c3c5e624b322db5d1710.png\" alt=\"\" title=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2013-11-19 6.28.12\" width=\"54\" height=\"41\" class=\"alignnone size-full wp-image-4826\" \/><\/a><\/p>\n<p>\u3068\u3001\u51c4\u304f\u9577\u304f\u306a\u308b\u3053\u3068\u304c\u5224\u660e\u3057\u307e\u3057\u305f\u306e\u3067\u3001Array Functions \u306f\u6b21\u56de\u3067\u3001\u5206\u3051\u3066\u3044\u304d\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>underscore.js \u3069\u3082\u3002 \u4e16\u9593\u3067\u306f\u3001\u306a\u3093\u3061\u3083\u3089js\u304c\u591a\u304f\u6ea2\u308c\u3066\u3044\u3066\u3001\u4f55\u304c\u306a\u3093\u3084\u3089\u3067\u5927\u5909\u3067\u3059\u306d\u3002 \u3067\u3082\u3001\u305d\u3093\u306a\u306a\u3093\u3061\u3083\u3089js\u304c\u7686\u3055\u3093\u597d\u304d\u306a\u306e\u304b\u3082\u77e5\u308c\u307e\u305b\u3093\u306d\u3002 \u3068\u3001\u305d\u3093\u306a\u611f\u3058\u3067\u3001\u4eca\u56de\u306f\u767b\u5834\u3057\u3066\u3061\u3087\u3063\u3068\u7d4c\u3061\u307e\u3059\u304c\u3001 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[167,177,168,176,40,166,37,47,179,50,46,169,78,114,118],"class_list":["post-4797","post","type-post","status-publish","format-standard","hentry","category-javascript","tag-css","tag-css3","tag-html","tag-html5","tag-ios-sdk","tag-iphone","tag-iphone-","tag-javascript-2","tag-jquery","tag-jquery-mobile","tag-js","tag-mac","tag-78","tag-114","tag-118"],"_links":{"self":[{"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/posts\/4797","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4797"}],"version-history":[{"count":14,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/posts\/4797\/revisions"}],"predecessor-version":[{"id":4836,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/posts\/4797\/revisions\/4836"}],"wp:attachment":[{"href":"https:\/\/www.webcyou.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4797"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4797"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4797"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}