| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/String/slice | [Back] [Original] |
Get to know MDN better
const str = "The quick brown fox jumps over the lazy dog.";
console.log(str.slice(31));
// : "the lazy dog."
console.log(str.slice(4, 19));
// : "quick brown fox"
console.log(str.slice(-4));
// : "dog."
console.log(str.slice(-9, -5));
// : "lazy"
slice(indexStart)
slice(indexStart, indexEnd)
slice() 1
slice() indexEnd indexEnd str.slice(4, 8) 5 8 4567
indexStart indexEnd
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
| T | h | e | | m | i | r | r | o | r |
m i r r
_______________
Result
indexStart >= str.length indexStart < 0 max(indexStart + str.length, 0) indexStart undefined 0 indexEnd undefined indexEnd >= str.length slice() indexEnd < 0 max(indexEnd + str.length, 0) indexEnd <= indexStart indexEnd indexStart slice()
const str1 = "The morning is upon us."; // The length of str1 is 23.
const str2 = str1.slice(1, 8);
const str3 = str1.slice(4, -2);
const str4 = str1.slice(12);
const str5 = str1.slice(30);
console.log(str2); // he morn
console.log(str3); // morning is upon u
console.log(str4); // is upon us.
console.log(str5); // ""
slice()
const str = "The morning is upon us.";
str.slice(-3); // 'us.'
str.slice(-3, -1); // 'us'
str.slice(0, -1); // 'The morning is upon us'
str.slice(4, -1); // 'morning is upon us'
11 16
console.log(str.slice(-11, 16)); // "is u"
11 7
console.log(str.slice(11, -7)); // " is u"
5 1
console.log(str.slice(-5, -1)); // "n us"
| ECMAScript 2027 LanguageSpecification # sec-string.prototype.slice |
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 |