@stdlib/array-base-without
v0.1.1
Published
Return a new array containing every element from an input array, except for the element at a specified index.
Downloads
2,356
Readme
without
Return a new array containing every element from an input array, except for the element at a specified index.
Installation
npm install @stdlib/array-base-withoutUsage
var without = require( '@stdlib/array-base-without' );without( x, index )
Returns a new array containing every element from an input array, except for the element at a specified index.
var x = [ 1, 2, 3, 4 ];
var out = without( x, 0 );
// returns [ 2, 3, 4 ]
out = without( x, -1 );
// returns [ 1, 2, 3 ]The function accepts the following arguments:
- x: an input array.
- index: element index.
without.assign( x, index, out, stride, offset )
Copies every element from one array to another array, except for the element at a specified index.
var x = [ 1, 2, 3, 4 ];
var out = [ 0, 0, 0 ];
var arr = without.assign( x, 0, out, 1, 0 );
// returns [ 2, 3, 4 ]
var bool = ( arr === out );
// returns trueThe function accepts the following arguments:
- x: an input array.
- index: element index.
- out: output array.
- stride: output array stride.
- offset: output array offset.
Notes
- Negative indices are resolved relative to the last array element, with the last element corresponding to
-1.
Examples
var discreteUniform = require( '@stdlib/random-array-discrete-uniform' );
var without = require( '@stdlib/array-base-without' );
// Define an array:
var opts = {
'dtype': 'generic'
};
var x = discreteUniform( 5, -100, 100, opts );
// Define an array containing random index values:
var indices = discreteUniform( 100, -x.length, x.length-1, opts );
// Randomly omit elements from the input array:
var i;
for ( i = 0; i < indices.length; i++ ) {
console.log( 'x = [%s]', without( x, indices[ i ] ).join( ',' ) );
}Notice
This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
Community
License
See LICENSE.
Copyright
Copyright © 2016-2026. The Stdlib Authors.
