{"id":570,"date":"2022-12-30T23:53:13","date_gmt":"2022-12-30T14:53:13","guid":{"rendered":"http:\/\/attacktube.com\/?p=570"},"modified":"2022-12-31T16:42:06","modified_gmt":"2022-12-31T07:42:06","slug":"javascript-indexof%e3%83%a1%e3%82%bd%e3%83%83%e3%83%89","status":"publish","type":"post","link":"https:\/\/attacktube.com\/?p=570","title":{"rendered":"JavaScript indexOf\u30e1\u30bd\u30c3\u30c9"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">indexOf\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3063\u3066\u5bfe\u8c61\u6587\u5b57\u5217\u304b\u3089search\u6587\u5b57\u5217\u304c\u691c\u7d22\u53ef\u80fd\u3067\u3042\u308b\u3002<br>\u79c1\u306f\u3001\u6587\u5b57\u5217\u691c\u7d22\u306b\u306findexOf\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u7528\u3057\u3066\u3044\u308b\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">indexOf\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3063\u305f\u6587\u5b57\u5217\u691c\u7d22\u306f\u6b21\u306e3\u30d1\u30bf\u30fc\u30f3\u304c\u3042\u308b\u3002<br>(1)indexOf\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3063\u3066\u5bfe\u8c61\u6587\u5b57\u5217\u3068search\u6587\u5b57\u5217\u304c\u542b\u307e\u308c\u308b\u304b\u3092\u5224\u5b9a\u3059\u308b\u3002<br>(2)indexOf\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3063\u3066\u5bfe\u8c61\u6587\u5b57\u5217\u3068search\u6587\u5b57\u5217\u304c\u524d\u65b9\u4e00\u81f4\u3059\u308b\u304b\u3092\u5224\u5b9a\u3059\u308b\u3002<br>(3)indexOf\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3063\u3066\u5bfe\u8c61\u6587\u5b57\u5217\u3068search\u6587\u5b57\u5217\u304c\u5f8c\u65b9\u4e00\u81f4\u3059\u308b\u304b\u3092\u5224\u5b9a\u3059\u308b\u3002<\/p>\n\n\n\n<!--more-->\n\n\n\n<br>\n<script async=\"\" src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js?client=ca-pub-3461056110605997\" crossorigin=\"anonymous\"><\/script>\n<ins class=\"adsbygoogle\" style=\"display:block; text-align:center;\" data-ad-layout=\"in-article\" data-ad-format=\"fluid\" data-ad-client=\"ca-pub-3461056110605997\" data-ad-slot=\"3137443461\"><\/ins>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script>\n<br>\n\n\n\n<p class=\"wp-block-paragraph\">indexOf\u306e\u623b\u308a\u5024\u3068\u3057\u3066\u306f\u3001\u6307\u5b9a\u3055\u308c\u305f\u5024\u304c\u6700\u521d\u306b\u73fe\u308c\u305f\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u8fd4\u3059\u3002<br>\u6307\u5b9a\u3055\u308c\u305f\u5024\u3092\u898b\u3064\u3051\u3089\u308c\u306a\u3044\u5834\u5408\u306f\u300c-1\u300d\u3092\u8fd4\u3059\u3002<br>\u524d\u65b9\u4e00\u81f4\u3059\u308b\u5834\u5408\u306f\u300c0\u300d\u304c\u8fd4\u308b(search\u6587\u5b57\u5217\u304c\u6700\u521d\u306b\u73fe\u308c\u305f\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u8fd4\u3059)<br>\u3053\u308c\u306b\u3088\u3063\u3066\u3001<br>(1)\u306e\u5834\u5408\u306f\u300c-1\u300d\u4ee5\u5916\u306e\u5024\u304c\u8fd4\u308b\u3068\u5bfe\u8c61\u6587\u5b57\u5217\u306bsearch\u6587\u5b57\u5217\u304c\u542b\u307e\u308c\u308b\u3068\u8a00\u3048\u308b\u3002<br>(2)\u306e\u5834\u5408\u306f\u300c0\u300d\u304c\u8fd4\u308b\u3068\u5bfe\u8c61\u6587\u5b57\u5217\u306bsearch\u6587\u5b57\u5217\u304c\u524d\u65b9\u4e00\u81f4\u3059\u308b\u3068\u8a00\u3048\u308b\u3002<br>(3)\u306e\u5834\u5408\u306f\u5bfe\u8c61\u6587\u5b57\u5217\u3068search\u6587\u5b57\u5217\u3092\u305d\u308c\u305e\u308c\u53cd\u8ee2\u3055\u305b\u3066\u300c0\u300d\u304c\u8fd4\u308b\u3068\u5bfe\u8c61\u6587\u5b57\u5217\u306bsearch\u6587\u5b57\u5217\u304c\u5f8c\u65b9\u4e00\u81f4\u3059\u308b\u3068\u8a00\u3048\u308b\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6587\u5b57\u5217\u3092\u53cd\u8ee2\u3059\u308b\u306b\u306fstrrev\u95a2\u6570\u3092\u4f7f\u7528\u3059\u308b\u3002<br>strrev\u95a2\u6570\u306f<a href=\"https:\/\/locutus.io\/php\/strings\/strrev\/\">Locutus<\/a>\u304c\u4f5c\u6210\u3057\u305f\u7269\u3092\u4f7f\u3046\u3053\u3068\u306b\u3059\u308b\u3002<\/p>\n\n\n\n<pre><code>\nvar strrev = function(string) {\n    \/\/       discuss at: https:\/\/locutus.io\/php\/strrev\/\n    \/\/      original by: Kevin van Zonneveld (https:\/\/kvz.io)\n    \/\/      bugfixed by: Onno Marsman (https:\/\/twitter.com\/onnomarsman)\n    \/\/ reimplemented by: Brett Zamir (https:\/\/brett-zamir.me)\n    \/\/        example 1: strrev('Kevin van Zonneveld')\n    \/\/        returns 1: 'dlevennoZ nav niveK'\n    \/\/        example 2: strrev('a\\u0301haB')\n    \/\/        returns 2: 'Baha\\u0301' \/\/ combining\n    \/\/        example 3: strrev('A\\uD87E\\uDC04Z')\n    \/\/        returns 3: 'Z\\uD87E\\uDC04A' \/\/ surrogates\n    \/\/             test: 'skip-3'\n\n    string = string + ''\n\n    \/\/ Performance will be enhanced with the next two lines of code commented\n    \/\/ out if you don't care about combining characters\n    \/\/ Keep Unicode combining characters together with the character preceding\n    \/\/ them and which they are modifying (as in PHP 6)\n    \/\/ See https:\/\/unicode.org\/reports\/tr44\/#Property_Table (Me+Mn)\n    \/\/ We also add the low surrogate range at the beginning here so it will be\n    \/\/ maintained with its preceding high surrogate\n\n    const chars = [\n        '\\uDC00-\\uDFFF',\n        '\\u0300-\\u036F',\n        '\\u0483-\\u0489',\n        '\\u0591-\\u05BD',\n        '\\u05BF',\n        '\\u05C1',\n        '\\u05C2',\n        '\\u05C4',\n        '\\u05C5',\n        '\\u05C7',\n        '\\u0610-\\u061A',\n        '\\u064B-\\u065E',\n        '\\u0670',\n        '\\u06D6-\\u06DC',\n        '\\u06DE-\\u06E4',\n        '\\u06E7\\u06E8',\n        '\\u06EA-\\u06ED',\n        '\\u0711',\n        '\\u0730-\\u074A',\n        '\\u07A6-\\u07B0',\n        '\\u07EB-\\u07F3',\n        '\\u0901-\\u0903',\n        '\\u093C',\n        '\\u093E-\\u094D',\n        '\\u0951-\\u0954',\n        '\\u0962',\n        '\\u0963',\n        '\\u0981-\\u0983',\n        '\\u09BC',\n        '\\u09BE-\\u09C4',\n        '\\u09C7',\n        '\\u09C8',\n        '\\u09CB-\\u09CD',\n        '\\u09D7',\n        '\\u09E2',\n        '\\u09E3',\n        '\\u0A01-\\u0A03',\n        '\\u0A3C',\n        '\\u0A3E-\\u0A42',\n        '\\u0A47',\n        '\\u0A48',\n        '\\u0A4B-\\u0A4D',\n        '\\u0A51',\n        '\\u0A70',\n        '\\u0A71',\n        '\\u0A75',\n        '\\u0A81-\\u0A83',\n        '\\u0ABC',\n        '\\u0ABE-\\u0AC5',\n        '\\u0AC7-\\u0AC9',\n        '\\u0ACB-\\u0ACD',\n        '\\u0AE2',\n        '\\u0AE3',\n        '\\u0B01-\\u0B03',\n        '\\u0B3C',\n        '\\u0B3E-\\u0B44',\n        '\\u0B47',\n        '\\u0B48',\n        '\\u0B4B-\\u0B4D',\n        '\\u0B56',\n        '\\u0B57',\n        '\\u0B62',\n        '\\u0B63',\n        '\\u0B82',\n        '\\u0BBE-\\u0BC2',\n        '\\u0BC6-\\u0BC8',\n        '\\u0BCA-\\u0BCD',\n        '\\u0BD7',\n        '\\u0C01-\\u0C03',\n        '\\u0C3E-\\u0C44',\n        '\\u0C46-\\u0C48',\n        '\\u0C4A-\\u0C4D',\n        '\\u0C55',\n        '\\u0C56',\n        '\\u0C62',\n        '\\u0C63',\n        '\\u0C82',\n        '\\u0C83',\n        '\\u0CBC',\n        '\\u0CBE-\\u0CC4',\n        '\\u0CC6-\\u0CC8',\n        '\\u0CCA-\\u0CCD',\n        '\\u0CD5',\n        '\\u0CD6',\n        '\\u0CE2',\n        '\\u0CE3',\n        '\\u0D02',\n        '\\u0D03',\n        '\\u0D3E-\\u0D44',\n        '\\u0D46-\\u0D48',\n        '\\u0D4A-\\u0D4D',\n        '\\u0D57',\n        '\\u0D62',\n        '\\u0D63',\n        '\\u0D82',\n        '\\u0D83',\n        '\\u0DCA',\n        '\\u0DCF-\\u0DD4',\n        '\\u0DD6',\n        '\\u0DD8-\\u0DDF',\n        '\\u0DF2',\n        '\\u0DF3',\n        '\\u0E31',\n        '\\u0E34-\\u0E3A',\n        '\\u0E47-\\u0E4E',\n        '\\u0EB1',\n        '\\u0EB4-\\u0EB9',\n        '\\u0EBB',\n        '\\u0EBC',\n        '\\u0EC8-\\u0ECD',\n        '\\u0F18',\n        '\\u0F19',\n        '\\u0F35',\n        '\\u0F37',\n        '\\u0F39',\n        '\\u0F3E',\n        '\\u0F3F',\n        '\\u0F71-\\u0F84',\n        '\\u0F86',\n        '\\u0F87',\n        '\\u0F90-\\u0F97',\n        '\\u0F99-\\u0FBC',\n        '\\u0FC6',\n        '\\u102B-\\u103E',\n        '\\u1056-\\u1059',\n        '\\u105E-\\u1060',\n        '\\u1062-\\u1064',\n        '\\u1067-\\u106D',\n        '\\u1071-\\u1074',\n        '\\u1082-\\u108D',\n        '\\u108F',\n        '\\u135F',\n        '\\u1712-\\u1714',\n        '\\u1732-\\u1734',\n        '\\u1752',\n        '\\u1753',\n        '\\u1772',\n        '\\u1773',\n        '\\u17B6-\\u17D3',\n        '\\u17DD',\n        '\\u180B-\\u180D',\n        '\\u18A9',\n        '\\u1920-\\u192B',\n        '\\u1930-\\u193B',\n        '\\u19B0-\\u19C0',\n        '\\u19C8',\n        '\\u19C9',\n        '\\u1A17-\\u1A1B',\n        '\\u1B00-\\u1B04',\n        '\\u1B34-\\u1B44',\n        '\\u1B6B-\\u1B73',\n        '\\u1B80-\\u1B82',\n        '\\u1BA1-\\u1BAA',\n        '\\u1C24-\\u1C37',\n        '\\u1DC0-\\u1DE6',\n        '\\u1DFE',\n        '\\u1DFF',\n        '\\u20D0-\\u20F0',\n        '\\u2DE0-\\u2DFF',\n        '\\u302A-\\u302F',\n        '\\u3099',\n        '\\u309A',\n        '\\uA66F-\\uA672',\n        '\\uA67C',\n        '\\uA67D',\n        '\\uA802',\n        '\\uA806',\n        '\\uA80B',\n        '\\uA823-\\uA827',\n        '\\uA880',\n        '\\uA881',\n        '\\uA8B4-\\uA8C4',\n        '\\uA926-\\uA92D',\n        '\\uA947-\\uA953',\n        '\\uAA29-\\uAA36',\n        '\\uAA43',\n        '\\uAA4C',\n        '\\uAA4D',\n        '\\uFB1E',\n        '\\uFE00-\\uFE0F',\n        '\\uFE20-\\uFE26'\n    ]\n\n    const graphemeExtend = new RegExp('(.)([' + chars.join('') + ']+)', 'g')\n\n    \/\/ Temporarily reverse\n    string = string.replace(graphemeExtend, '$2$1')\n    return string.split('').reverse().join('')\n};\n\nvar searchWord = \"au\";\nvar buf = \"taunt\";\n\nif (buf.indexOf(searchWord) !== -1) {\n    \/\/\u5bfe\u8c61\u6587\u5b57\u5217\u306bsearch\u6587\u5b57\u5217\u304c\u542b\u307e\u308c\u308b\n    console.log(buf + \"\u306e\u4e2d\u306b\" + searchWord + \"\u304c\u542b\u307e\u308c\u308b\u3002\");\n} else {\n    \/\/\u5bfe\u8c61\u6587\u5b57\u5217\u306bsearch\u6587\u5b57\u5217\u304c\u542b\u307e\u308c\u306a\u3044\n    console.log(buf + \"\u306e\u4e2d\u306b\" + searchWord + \"\u304c\u542b\u307e\u308c\u306a\u3044\u3002\");\n}\n\nsearchWord = \"ta\";\n\nif (buf.indexOf(searchWord) === 0) {\n    \/\/\u5bfe\u8c61\u6587\u5b57\u5217\u3068search\u6587\u5b57\u5217\u304c\u524d\u65b9\u4e00\u81f4\u3059\u308b\n    console.log(buf + \"\u306e\u4e2d\u306b\" + searchWord + \"\u304c\u524d\u65b9\u4e00\u81f4\u3059\u308b\u3002\");\n} else {\n    \/\/\u5bfe\u8c61\u6587\u5b57\u5217\u306bsearch\u6587\u5b57\u5217\u304c\u524d\u65b9\u4e00\u81f4\u3057\u306a\u3044\n    console.log(buf + \"\u306e\u4e2d\u306b\" + searchWord + \"\u304c\u524d\u65b9\u4e00\u81f4\u3057\u306a\u3044\");\n}\n\nsearchWord = \"aunt\";\n\nif (strrev(buf).indexOf(strrev(searchWord)) === 0) {\n    \/\/\u5bfe\u8c61\u6587\u5b57\u5217\u3068search\u6587\u5b57\u5217\u304c\u5f8c\u65b9\u4e00\u81f4\u3059\u308b\n    console.log(\"buf\u306e\u53cd\u8ee2 strrev(buf) = \" + strrev(buf));\n    console.log(\"buf\u306e\u53cd\u8ee2 strrev(searchWord) = \" + strrev(searchWord));\n    console.log(buf + \"\u306e\u4e2d\u306b\" + searchWord + \"\u304c\u5f8c\u65b9\u4e00\u81f4\u3059\u308b\u3002\");\n} else {\n    console.log(\"buf\u306e\u53cd\u8ee2 strrev(buf) = \" + strrev(buf));\n    console.log(\"buf\u306e\u53cd\u8ee2 strrev(searchWord) = \" + strrev(searchWord));\n    \/\/\u5bfe\u8c61\u6587\u5b57\u5217\u306bsearch\u6587\u5b57\u5217\u304c\u5f8c\u65b9\u4e00\u81f4\u3057\u306a\u3044\n    console.log(buf + \"\u306e\u4e2d\u306b\" + searchWord + \"\u304c\u5f8c\u65b9\u4e00\u81f4\u3057\u306a\u3044\u3002\");\n}\n\n\/*\n\ntaunt\u306e\u4e2d\u306bau\u304c\u542b\u307e\u308c\u308b\u3002\ntaunt\u306e\u4e2d\u306bta\u304c\u524d\u65b9\u4e00\u81f4\u3059\u308b\u3002\nbuf\u306e\u53cd\u8ee2 strrev(buf) = tnuat\nbuf\u306e\u53cd\u8ee2 strrev(searchWord) = tnua\ntaunt\u306e\u4e2d\u306baunt\u304c\u5f8c\u65b9\u4e00\u81f4\u3059\u308b\u3002\n*\/\n\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5f8c\u65b9\u4e00\u81f4\u306f\u6b21\u306e\u3088\u3046\u306b\u534a\u89d2\u30b9\u30da\u30fc\u30b91\u6587\u5b57\u5206\u3092\u6587\u5b57\u5217\u306b\u9023\u7d50\u3055\u305b\u305f\u6587\u5b57\u5217\u540c\u58eb\u3092\u6bd4\u8f03\u3059\u308b\u3053\u3068\u306b\u3088\u308a\u3001\u5f8c\u65b9\u4e00\u81f4\u3059\u308b\u304b\u3057\u306a\u3044\u304b\u306e\u5224\u5b9a\u304c\u53ef\u80fd\u3060\u304c\u3001\u3053\u306e\u534a\u89d2\u30b9\u30da\u30fc\u30b91\u6587\u5b57\u5206\u3092\u9023\u7d50\u3055\u305b\u308b\u30b3\u30fc\u30c9\u306f\u8aad\u307f\u305a\u3089\u304f\u3001\u4f55\u3092\u3084\u3063\u3066\u3044\u308b\u304b\u304c\u3044\u307e\u3044\u3061\u5206\u304b\u308a\u305a\u3089\u3044\u6c17\u304c\u3059\u308b\u306e\u3067\u3001\u5f8c\u65b9\u4e00\u81f4\u306f\u6587\u5b57\u5217\u3092\u53cd\u8ee2\u3055\u305b\u308bstrrev\u95a2\u6570\u3092\u4f7f\u7528\u3057\u30660\u304c\u3069\u3046\u304b\u306e\u5224\u5b9a\u306b\u3057\u305f\u3002\u3053\u3061\u3089\u306e\u65b9\u304c\u5206\u304b\u308a\u3084\u3059\u3044\u3068\u81ea\u5206\u3067\u306f\u601d\u3046\u3002\u597d\u307f\u304b\u3082\u3057\u308c\u306a\u3044\u3002<\/p>\n\n\n\n<pre><code>\nvar searchWord = &quot;aunt&quot;;\nvar buf = &quot;taunt&quot;;\nvar str = buf + &quot; &quot;;\n\nif (str.indexOf(searchWord + &quot; &quot;) !== -1) {\n    console.log(buf + &quot;\u306e\u4e2d\u306b&quot; + searchWord + &quot;\u304c\u5f8c\u65b9\u4e00\u81f4\u3059\u308b\u3002&quot;);\n}\n\n\/*\n\ntaunt\u306e\u4e2d\u306baunt\u304c\u5f8c\u65b9\u4e00\u81f4\u3059\u308b\u3002\n\n*\/\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u53c2\u8003<br><a href=\"https:\/\/nazomikan.hateblo.jp\/entry\/20110303\/1299167055\">\u5358\u8a9e\u524d\u65b9\u4e00\u81f4\u30fb\u5358\u8a9e\u5f8c\u65b9\u4e00\u81f4\u30fb\u5358\u8a9e\u5b8c\u5168\u4e00\u81f4 String.indexOf\u306e\u9b54\u529b<\/a><\/p>\n\n\n\n<script type=\"text\/javascript\">\njQuery(function($){\n$(\".jp-video\").hide();\n});\n<\/script>\n","protected":false},"excerpt":{"rendered":"<p>indexOf\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3063\u3066\u5bfe\u8c61\u6587\u5b57\u5217\u304b\u3089search\u6587\u5b57\u5217\u304c\u691c\u7d22\u53ef\u80fd\u3067\u3042\u308b\u3002\u79c1\u306f\u3001\u6587\u5b57\u5217\u691c\u7d22\u306b\u306findexOf\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u7528\u3057\u3066\u3044\u308b\u3002 indexOf\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3063\u305f\u6587\u5b57\u5217\u691c\u7d22\u306f\u6b21\u306e3\u30d1\u30bf\u30fc\u30f3\u304c\u3042\u308b\u3002(1)index [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3],"tags":[],"class_list":["post-570","post","type-post","status-publish","format-standard","hentry","category-javascript"],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/attacktube.com\/index.php?rest_route=\/wp\/v2\/posts\/570","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/attacktube.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/attacktube.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/attacktube.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/attacktube.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=570"}],"version-history":[{"count":10,"href":"https:\/\/attacktube.com\/index.php?rest_route=\/wp\/v2\/posts\/570\/revisions"}],"predecessor-version":[{"id":613,"href":"https:\/\/attacktube.com\/index.php?rest_route=\/wp\/v2\/posts\/570\/revisions\/613"}],"wp:attachment":[{"href":"https:\/\/attacktube.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=570"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/attacktube.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=570"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/attacktube.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=570"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}