Special method ‣ subarray(start, end) - chung-leong/zigar GitHub Wiki

This method returns a portion of the pointer's target, indicated by startand end (not inclusive). Negative indices are counted from the end of the parent slice. Example:

pub const PtrI32 = []i32;
import { PtrI32 } from './subarray-example-1.zig';

const sliceO = new PtrI32([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]);
const sliceA = sliceO.subarray(1, 5);
console.log('sliceA before:', [ ...sliceA ]);
sliceA[0] = 100;
console.log('sliceA after:', [ ...sliceA ]);
console.log('sliceO after:', [ ...sliceO ]);

const sliceB = sliceO.subarray(-9, -1);
console.log('sliceB:', [ ...sliceB ]);

const sliceC = sliceO.subarray();
console.log('sliceC:', [ ...sliceC ]);
sliceA before: [ 1, 2, 3, 4 ]
sliceA after: [ 100, 2, 3, 4 ]
sliceO after: [
  0, 100, 2, 3, 4,
  5,   6, 7, 8, 9
]
sliceB: [
  100, 2, 3, 4,
    5, 6, 7, 8
]
sliceC: [
  0, 100, 2, 3, 4,
  5,   6, 7, 8, 9
]```

---
[Special methods](Special-methods)