“slice () javascript” Réponses codées

javascript obtient un sous-tableau

var fruits = ["Banana", "Orange", "Lemon", "Apple", "Mango"];
var citrus = fruits.slice(1, 3);
// ["Orange", "Lemon"]
Mattalui

slice () 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

Index du tableau JavaScript n'afficher que les 2 premiers éléments

array.slice(0, n);
MysteriousButterfly

Split () javascript

let countWords = function(sentence){
    return sentence.split(' ').length;
}

console.log(countWords('Type any sentence here'));

//result will be '4'(for words in the sentence)
Rodrigo Palazon

tranche javascrip

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

Réponses similaires à “slice () javascript”

Questions similaires à “slice () javascript”

Plus de réponses similaires à “slice () javascript” dans JavaScript

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code