

Reducing the range of any index to a single value effectively eliminates that index. In programming languages that use a 0-based indexing scheme, the slice would be from index 2 to 5. Thus, if we have a vector containing elements (2, 5, 7, 3, 8, 6, 4, 1), and we want to create an array slice from the 3rd to the 6th items, we get (7, 3, 8, 6).

Also depending on the language, the elements of the new array may be aliased to (i.e., share memory with) those of the original array.įor "one-dimensional" (single-indexed) arrays – vectors, sequence, strings etc. – the most common slicing operation is extraction of zero or more consecutive elements. In computer programming, array slicing is an operation that extracts a subset of elements from an array and packages them as another array, possibly in a different dimension from the original.Ĭommon examples of array slicing are extracting a substring from a string of characters, the " ell" in "h ello", extracting a row or column from a two-dimensional array, or extracting a vector from a matrix.ĭepending on the programming language, an array slice can be made out of non-consecutive elements. For other uses of slicing, see Slicing (disambiguation). This article is about the data structure operation.
