“mengiris” Kode Jawaban

mengembalikan dua nilai array terakhir dalam javascript

arr.slice(Math.max(arr.length - 5, 1))
Fancy Fox

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

Array Salin JavaScript

var oldColors=["red","green","blue"];
var newColors = oldColors.slice(); //make a clone/copy of oldColors
Grepper

Array hanya memotong 5 elemen terakhir

arr.slice(Math.max(arr.length - 5, 0))
Condemned Camel

JavaScript Cara Mendapatkan Subarray

const ar  = [1, 2, 3, 4, 5];

// slice from 1..3 - add 1 as the end index is not included

const ar2 = ar.slice(1, 3 + 1);

console.log(ar2);
Stormy Seal

mengiris

Concept:
s[x:y:z] , x- left index , y-1 - right index 
z is the number of steps of jumping between 2 chr 
if z>0 :
    direction of jump is right to left(R2L)
else:
    direction of jump is left to right(L2R)
s[:3] means x=0,y=2,z=1
s[3:] means x=3,y=len(s)-1,z=1

examples:

s="dbdhdhndnbdd"
print(s[2:6:2])
//prints dd as left index is 2 right is 5 -> substring is dhdh & 2 means d,skip h,then d
s="djdjcjfd"
print(s[::-2])
//prints djjj, left index is 0 ,right is len(s)-1 -> substring is djdjcjfd & 
//-2 means start from right side in substring in steps of 2-> d,skip f,then j,skip c,then j & j
ap_Cooperative_dev

Jawaban yang mirip dengan “mengiris”

Pertanyaan yang mirip dengan “mengiris”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya