This page has been moved to the Programmer's Wiki.
Please do not make any changes or additions to this page. Any modifications, if still appropriate, should be made on Array slice at the Programmer's Wiki. |
function array_slice(arr, offst, lgth) {
if (lgth === undefined) {
return arr.slice(offst);
}
else {
if (lgth > 0) {
return arr.slice(offst, offst + lgth);
}
else if (lgth < 0) {
return arr.slice(offst, lgth);
}
}
}
Example Javascript Usage
arr1 = new Array("a1", "a2", "a3", "a4", "a5");
alert(array_slice(arr1, 2)); /* Returns: a3,a4,a5 */
alert(array_slice(arr1, -2, 1)); /* Returns: a4 */
alert(array_slice(arr1, 0, 3)); /* Returns: a1,a2,a3 */
alert(array_slice(arr1, 2, -1)); /* Returns: a3,a4 */