@stdlib/array-base-remove-at
v0.1.1
Published
Remove an element from an array.
Downloads
55
Readme
removeAt
Remove an element from an array.
Installation
npm install @stdlib/array-base-remove-atUsage
var removeAt = require( '@stdlib/array-base-remove-at' );removeAt( x, index )
Removes an element from an array.
var x = [ 1, 1, 2, 3, 3 ];
var y = removeAt( x, -3 );
// returns [ 1, 1, 3, 3 ]
var bool = ( x === y );
// returns trueThe function accepts the following arguments:
- x: an input array.
- index: element index.
Notes
- Negative indices are resolved relative to the last array element, with the last element corresponding to
-1. - If provided out-of-bounds indices, the function returns the input array unchanged; otherwise, the function mutates the input array.
Examples
var discreteUniform = require( '@stdlib/random-array-discrete-uniform' );
var randi = require( '@stdlib/random-base-discrete-uniform' );
var removeAt = require( '@stdlib/array-base-remove-at' );
// Create an array of random numbers:
var x = discreteUniform( 10, 0, 5, {
'dtype': 'generic'
});
// returns [...]
console.log( x );
// Remove a random element:
var y = removeAt( x, randi( 0, x.length-1 ) );
// returns [...]
console.log( y );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.
