“метод среза в JS” Ответ

метод среза в JS

// array.slice(start, end)
const FRUITS = ["Banana", "Orange", "Lemon", "Apple", "Mango"];
var citrus = FRUITS.slice(1, 3);
// citrus => [ 'Orange', 'Lemon' ]

// Negative values slice in the opposite direction
var fromTheEnd = FRUITS.slice(-3, -1);
// fromTheEnd => [ 'Lemon', 'Apple' ]
deadlymuffin

Slice JavaScript

const string="Hi my name is mezen";
string.slice (2); // return string without the character of index 2;
string.slice (6); // return string without the character of index 6;

string.slice (3,7) /* return 'my na' (m of index 3; a of index 7) including the
                      blank spaces */
The Code Slayer

JS Slice

//The slice() method extracts a section of a string and returns 
//it as a new string, without modifying the original string.

// same in array but you select elements not characters  


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"
mikelikestocode

Пример среза

/*Use string concatenation and two slice() methods to print
'JS' from 'JavaScript'.*/

let language = 'JavaScript';
console.log(language.slice(0,1)+language.slice(4,5));

//JS
Tough Tortoise

Среза в JS

//The slice() method extracts a section of a string and returns 
//it as a new string, without modifying the original string.
Talented Trout

Функция JavaScript slice ()


var fruits = new Array ( "apple", "pear", "orange", "banana" );
alert ( fruits.slice ( 1, 3 ) )  // Displays "pear,orange"
alert ( fruits.slice ( 0, -2 ) ) // Displays "apple,pear"
alert ( fruits.slice ( 2 ) )     // Displays "orange,banana"
JulisTaf

Ответы похожие на “метод среза в JS”

Вопросы похожие на “метод среза в JS”

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

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

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