| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/String/slice | [Back] [Original] |
Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
This feature is well established and works across many devices and browser versions. Its been available across browsers since 2015 ..
slice() .
const str = "The quick brown fox jumps over the lazy dog.";
console.log(str.slice(31));
// Expected output: "the lazy dog."
console.log(str.slice(4, 19));
// Expected output: "quick brown fox"
console.log(str.slice(-4));
// Expected output: "dog."
console.log(str.slice(-9, -5));
// Expected output: "lazy"
str.slice(beginIndex[, endIndex])
beginIndex, ( ). , str.length + beginIndex (, beginIndex -3, str.length - 3). beginIndex Number(beginIndex), 0.
beginIndex str.length, .
endIndex, ( ). .
*endIndex * undefined str.length, slice() . , str.length + endIndex (, endIndex -3, str.length - 3). undefined Number(endIndex), .
endIndex startIndex, (, slice(-1, -3) slice(3, 1) "").
, .
slice() . .
slice() endIndex, . str.slice(1, 4) ( 1, 2 3).
, str.slice(2, -1) .
slice() slice() .
let str1 = " .";
let str2 = str1.slice(1, 8);
let str3 = str1.slice(4, -2);
let str4 = str1.slice(12);
let str5 = str1.slice(30);
console.log(str2); // :
console.log(str3); // :
console.log(str4); // : .
console.log(str5); // : ""
slice() slice() .
let str = " .";
str.slice(-3); // '.'
str.slice(-3, -1); // ''
str.slice(0, -1); // ' '
11- , - 16- .
str.slice(-11, 16); // ' '
6- , - 7- .
str.slice(6, -7); // ''
: 5- , 1- .
str.slice(-5, -1); // ''
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-string.prototype.slice |
This page was last modified on 24 . 2025 . by MDN contributors.
StringString.prototype.anchor()at()String.prototype.big()String.prototype.blink()String.prototype.bold()String.prototype.charAt()String.prototype.charCodeAt()String.prototype.codePointAt()String.prototype.concat()String.prototype.endsWith()String.prototype.fixed()String.prototype.fontcolor()String.prototype.fontsize()String.prototype.includes()String.prototype.indexOf()isWellFormed()String.prototype.italics()String.prototype.lastIndexOf()String.prototype.link()String.prototype.localeCompare()String.prototype.match()String.prototype.matchAll()String.prototype.normalize()String.prototype.padEnd()String.prototype.padStart()String.prototype.repeat()String.prototype.replace()String.prototype.replaceAll()String.prototype.search()String.prototype.slice()String.prototype.small()String.prototype.split()String.prototype.startsWith()String.prototype.strike()String.prototype.sub()String.prototype.substr()String.prototype.substring()String.prototype.sup()String.prototype.toLocaleLowerCase()String.prototype.toLocaleUpperCase()String.prototype.toLowerCase()String.prototype.toString()String.prototype.toUpperCase()toWellFormed()String.prototype.trim()String.prototype.trimRight()String.prototype.trimLeft()String.prototype.valueOf()String.prototype[@@iterator]()Object/FunctionObject.prototype.__defineGetter__()Object.prototype.__defineSetter__()Object.prototype.__lookupGetter__()Object.prototype.__lookupSetter__()Object.prototype.hasOwnProperty()Object.prototype.isPrototypeOf()Object.prototype.propertyIsEnumerable()Object.prototype.toLocaleString()Object.prototype.toString()Object.prototype.valueOf()Your blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |