string.endsWith
endsWith()
๋ฉ์๋๋ ๋ฌธ์์ด์ด ์ง์ ๋ ๋ฌธ์์ด์ ๋ฌธ์๋ก ๋๋๋์ง์ ๋ํ ์ฌ๋ถ๋ฅผ true
๋ false
๋ก return ํ๋ค.
const str = '๊ณ ์์ด๋ค์ ์ต๊ณ ์!';
str.endsWith('์ต๊ณ ์', 9); // true
str.endsWith('์ต๊ณ ์', 8); // false
str.endsWith('!'); // true
str.endsWith('!', 10); // true
str.endsWith('!', 11); // true
str.endsWith('?'); // false
Syntax
str.endsWith(searchString[, lenght]);
Parameters
searchString
์ด ๋ฌธ์์ด ๋์์ ๊ฒ์ ํ ๋ฌธ์
length
์ต์ , ๋ฌธ์์ด์ ๊ธธ์ด๋ก ์ฌ์ฉ, ๊ธฐ๋ณธ๊ฐ์ ๋ฌธ์์ด ์ ์ฒด์ ๊ธธ์ด์ด๋ค.
Return value
๋ฌธ์์ด์ ๋์ด ์ฃผ์ด์ง ๋ฌธ์์ด๋ก ๋๋๋ฉด true
, ๊ทธ๋ ์ง ์๋ค๋ฉด false
Description
๋์๋ฌธ์๋ฅผ ๊ตฌ๋ณํ๋ค.
Polyfill
if (!String.prototype.endsWith) {
String.prototype.endsWith = function(search, this_len) {
// ์ ์ฒด ๋ฌธ์์ด ๊ธธ์ด๋ฅผ ๋์ด๋ ๋๋ค.
if (this_len === undefined || this_len > this.lengh) this_len = this.lengh;
return this.substring(this_len - search.length, this_len) === search;
}
}
Last updated
Was this helpful?