“Metode Slice JavaScript” Kode Jawaban

JavaScript mendapatkan sub array

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

JavaScript Slice Array

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

Iris 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

Iris Javascript

  arr.slice(1).map((_, i) => [arr.slice(0, i + 1), arr.slice(i + 1)]);
Maeron Reyes

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

Metode Slice JavaScript

const strings = ["fred", "esther","sarah","favour","abraham","isaac","idemudia"]

const capitalStrings = strings.map((name) => {
  return name[0].toUpperCase() + name.slice(1)
})

console.log(capitalStrings)

// Expected result: [
//   "Fred",
//   "Esther",
//   "Sarah",
//   "Favour",
//   "Abraham",
//   "Isaac",
//   "Idemudia"
// ]
Fredrick Idemudia

Jawaban yang mirip dengan “Metode Slice JavaScript”

Pertanyaan yang mirip dengan “Metode Slice JavaScript”

Lebih banyak jawaban terkait untuk “Metode Slice JavaScript” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya