1. Home
  2. Docs
  3. JAVASCRIPT
  4. 字串
  5. 字串長度 str.length

字串長度 str.length

<!DOCTYPE html>
<html>
<body>

<p>Click the button to return the number of characters in the string "Hello World!".</p>

<button onclick="myFunction()">Try it</button>

<p id="demo"></p>

<script>
function myFunction() {
  var str = "Hello World!";
  var n = str.length;
  document.getElementById("demo").innerHTML = n;
}
</script>

</body>
</html>