Fandom

Programmer's Wiki

Array slice

406pages on
this wiki
Add New Page
Talk0 Share
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 UsageEdit

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

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.