This website collects cookies to deliver better user experience
>> myArray = ['a','b','c','d','e','f','g', 'h', 'i'] >> myArray[0..4] => ['a','b','c', 'd', 'e']
Ruby
array.slice(begin [, end])
var myArray = ['a','b','c','d','e','f','g', 'h','i']; var sliced = myArray.slice(0, 5); //will contain ['a', 'b', 'c','d', 'e']
end
myArray[m..n]
Javascript
myArray.slice(m, n+1);
the second argument to slice in Ruby is the length, but in JavaScript it is the index of the last element.
JavaScript
var myArray = ['a','b','c','d','e','f','g', 'h','i']; var lastThree = myArray.slice(-3); //g, h, i
slice
arr.length
var myArray = ['a','b','c','d','e','f','g', 'h','i']; var noEndInSlice = myArray.slice(5); //f, g, h, i
which indicate that the end value is optional
37
1