| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/String/at | [Back] [Original] |
Get to know MDN better
const sentence = "The quick brown fox jumps over the lazy dog.";
let index = 5;
console.log(`An index of ${index} returns the character ${sentence.at(index)}`);
// : "An index of 5 returns the character u"
index = -4;
console.log(`An index of ${index} returns the character ${sentence.at(index)}`);
// : "An index of -4 returns the character d"
at(index)
UTF-16 undefined
//
function returnLast(str) {
return str.at(-1);
}
let invoiceRef = "my-invoice01";
console.log(returnLast(invoiceRef)); // '1'
invoiceRef = "my-invoice02";
console.log(returnLast(invoiceRef)); // '2'
2 at()
const myString = "Every green bus drives fast.";
// length charAt()
const lengthWay = myString.charAt(myString.length - 2);
console.log(lengthWay); // 't'
// slice()
const sliceWay = myString.slice(-2, -1);
console.log(sliceWay); // 't'
// at()
const atWay = myString.at(-2);
console.log(atWay); // 't'
| ECMAScript 2027 LanguageSpecification # sec-string.prototype.at |
Stringanchor()at()big()blink()bold()charAt()charCodeAt()codePointAt()concat()endsWith()fixed()fontcolor()fontsize()includes()indexOf()isWellFormed()italics()lastIndexOf()link()localeCompare()match()matchAll()normalize()padEnd()padStart()repeat()replace()replaceAll()search()slice()small()split()startsWith()strike()sub()substr()substring()sup()toLocaleLowerCase()toLocaleUpperCase()toLowerCase()toString()toUpperCase()toWellFormed()trim()trimEnd()trimStart()valueOf()[Symbol.iterator]()Object/Function| Web Proxy Viewer | New URL | Original Page |