“JavaScript Slice и подстроение” Ответ

Подстроение в JavaScript с помощью Slice

let str = "Learning to code";

// slice between index 0 and index 5
console.log(str.slice(0, 5));
// slice between index 5 and index 10
console.log(str.slice(5, 10));
Clumsy Caiman

JavaScript Slice и подстроение

string.slice(start, stop);
string.substring(start, stop);

What they have in common:

-If start equals stop: returns an empty string
-If stop is omitted: extracts characters to the end of the string
-If either argument is greater than the string's length, the string's length 
will be used instead.
    
Distinctions of substring():

-If start > stop, then substring will swap those 2 arguments.
-If either argument is negative or is NaN, it is treated as if it were 0.

Distinctions of slice():

-If start > stop, slice() will return the empty string. ("")
-If start is negative: sets char from the end of string.
-If stop is negative: sets stop to: string.length – Math.abs(stop) 
(original value), except bounded at 0.   
ramon bastos

Ответы похожие на “JavaScript Slice и подстроение”

Вопросы похожие на “JavaScript Slice и подстроение”

Больше похожих ответов на “JavaScript Slice и подстроение” по JavaScript

Смотреть популярные ответы по языку

Смотреть другие языки программирования