pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith

ript>

このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。

View in English Always switch to English

String.prototype.startsWith()

Baseline 広く利用可能

この機能は広く実装されており、多くのバージョンの端末やブラウザーで動作します。2015年9月以降、すべてのブラウザーで利用可能です。

startsWith()String 値のメソッドで、文字列が引数で指定された文字列で始まるかを判定して truefalse を返します。

試してみましょう

const str = "Saturday night plans";

console.log(str.startsWith("Sat"));
// 予想される結果: true

console.log(str.startsWith("Sat", 3));
// 予想される結果: false

構文

js
startsWith(searchString)
startsWith(searchString, position)

引数

searchString

str の先頭で検索される文字の集合です。正規表現にすることはできません。正規表現ではない値はすべて文字列に変換されますので、省略したり undefined を渡したりすると、startsWith()"undefined" という文字列を検索します。これはおそらく望むところではないでしょう。

position 省略可

searchString が見つかると期待される開始位置(searchString の先頭の文字のインデックス)です。既定値は 0 です。

返値

文字列が指定された文字列で始まる場合、searchString が空文字列の場合は true、それ以外の場合は false です。

例外

TypeError

searchString正規表現であった場合。

解説

文字列が特定の文字列で終わるかどうかを判断できます。このメソッドでは(英文字の)大文字小文字は区別されます。

startsWith() の使用

js
const str = "To be, or not to be, that is the question.";

console.log(str.startsWith("To be")); // true
console.log(str.startsWith("not to be")); // false
console.log(str.startsWith("not to be", 10)); // true

仕様書

仕様書
ECMAScript® 2027 Language Specification
# sec-string.prototype.startswith

ブラウザーの互換性

関連情報

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy