Programmer's Wiki
Advertisement
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 */
Advertisement