@stdlib/array
Version:
Arrays.
130 lines (77 loc) • 2.82 kB
Markdown
<!--
@license Apache-2.0
Copyright (c) 2022 The Stdlib Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
# copy
> Copy the elements of an array-like object to a new "generic" array.
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
<section class="intro">
</section>
<!-- /.intro -->
<!-- Package usage documentation. -->
<section class="usage">
## Usage
```javascript
var copy = require( '@stdlib/array/base/copy' );
```
#### copy( x )
Copies the elements of an array-like object to a new "generic" array.
```javascript
var x = [ 1, 2, 3 ];
var out = copy( x );
// returns [ 1, 2, 3 ]
var bool = ( out === x );
// returns false
```
</section>
<!-- /.usage -->
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
<section class="notes">
</section>
<!-- /.notes -->
<!-- Package usage examples. -->
<section class="examples">
## Examples
<!-- eslint no-undef: "error" -->
```javascript
var Complex64Array = require( '@stdlib/array/complex64' );
var realf = require( '@stdlib/complex/float32/real' );
var imagf = require( '@stdlib/complex/float32/imag' );
var copy = require( '@stdlib/array/base/copy' );
// Create a complex number array:
var arr = new Complex64Array( 10 );
// Copy elements to a generic array:
var out = copy( arr );
// Retrieve the first element:
var z = out[ 0 ];
// returns <Complex64>
var re = realf( z );
// returns 0.0
var im = imagf( z );
// returns 0.0
console.log( '%d + %di', re, im );
// => '0 + 0i'
```
</section>
<!-- /.examples -->
<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
<section class="references">
</section>
<!-- /.references -->
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
<section class="related">
</section>
<!-- /.related -->
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
<section class="links">
</section>
<!-- /.links -->