“JavaScript Array Slice ()” Réponses codées

tableau de tranche javascript

// 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

array.slice

const animals = ['ant', 'bison', 'camel', 'duck', 'elephant'];

console.log(animals.slice(2));
// expected output: Array ["camel", "duck", "elephant"]

console.log(animals.slice(2, 4));
// expected output: Array ["camel", "duck"]

console.log(animals.slice(1, 5));
// expected output: Array ["bison", "camel", "duck", "elephant"]
Precious Puma

Fonction 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

JavaScript Array Slice ()

const fruits = ["Banana", "Orange", "Lemon", "Apple", "Mango"];
const citrus = fruits.slice(1);
naly moslih

Réponses similaires à “JavaScript Array Slice ()”

Questions similaires à “JavaScript Array Slice ()”

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code