String.prototype.length - 文字列の長さ
String.prototype.lengthは、文字列の長さを返すプロパティです。
概要
- 名前
- length
- 所属
- String.prototype
- Writable
- no
- Enumerable
- no
- Configurable
- no
- 仕様書
- https://tc39.github.io/ecma262/#sec-properties-of-string-instances-length
デモ
String.prototype.lengthのデモです。
<!-- このコードは編集できます。 -->
<!DOCTYPE html>
<html>
<head>
<style>
body {
white-space: pre-wrap ;
}
</style>
</head>
<body>
<script>
/** try it! **/
var string = "SYNCERあいうえお" ;
var a = string.length ;
/** try it! **/
var results = { a:a, } ;
for( var name in results ) {
console.log( name, results[name] ) ;
document.body.appendChild( new Text( name + " = " + JSON.stringify( results[name] ) + "\n" ) ) ;
}
</script>
</body>
</html>
サポート状況
Chrome | Firefox | Safari | Edge | IE | Opera | iOS Safari | Android |
---|---|---|---|---|---|---|---|
● | ● | ● | ● | ● 9+ | ● | ● | ● |
関連記事
- String.prototype.padEnd()
- String.prototype.padEnd()は、元の文字列を指定した長さに変更するメソッドです。長さが足りない場合は指定した文字列を末尾に繰り返しで追加します。
- UNIXタイムスタンプを取得する
- JavaScriptでPHPのtime()、strtotime()と同じようにUNIX TIMESTAMPを取得します。
- String.prototype.valueOf()
- String.prototype.valueOf()は、Stringのプリミティブ値を返すメソッドです。toString()と同じ値を取得できます。
- String.prototype.constructor
- String.prototype.constructorはコンストラクタのStringを返すプロパティです。