String JavaScript termasuk()
Contoh
Periksa apakah string menyertakan "dunia":
let text = "Hello world, welcome to the universe.";
let result = text.includes("world");
let text = "Hello World, welcome to the universe.";
let result = text.includes("world", 12);
Lebih banyak contoh di bawah ini.
Definisi dan Penggunaan
Metode includes()
kembali true
jika string berisi string tertentu.
Jika tidak, ia kembali false
.
Metode includes()
ini peka huruf besar/kecil.
Sintaksis
string.includes(searchvalue, start)
Parameter
Parameter | Description |
searchvalue | Required. The string to search for. |
start | Optional. The position to start from. Default value is 0. |
Nilai Kembali
Jenis | Keterangan |
Sebuah boolean. | true jika string berisi nilai, jika tidak false . |
Lebih Banyak Contoh
Mulai dari posisi 12:
let text = "Hello world, welcome to the universe.";
let result = text.includes("world", 12);
Dukungan Peramban
includes()
adalah fitur ECMAScript6 (ES6).
ES6 (JavaScript 2015) didukung di semua browser modern:
Chrome | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes |
includes()
tidak didukung di Internet Explorer 11 (atau lebih lama).