文字列からいくつかの文字を抽出しようとしています。私はこれらのコードを使用してexample at hereを試してみました:yyyy/mm/dd
として特殊文字 '/'を含む文字列のJavascript部分文字
<!DOCTYPE html>
<html>
<body>
<p>Click the button to extract parts of the string.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
var str = "2017/01/23";
var res = str.substr(5, 6);
document.getElementById("demo").innerHTML = res;
}
</script>
</body>
</html>
私の日付形式と私は月を抽出したかったです。しかし、上記のコードでは、substr(5,6)
を試したときに'01
'ではなく'01/23'
が返されます。
愚かな間違いでした。それを指摘してくれてありがとう! :) – guest176969