|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2025 The Stdlib Authors. |
| 6 | +
|
| 7 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | +you may not use this file except in compliance with the License. |
| 9 | +You may obtain a copy of the License at |
| 10 | +
|
| 11 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +
|
| 13 | +Unless required by applicable law or agreed to in writing, software |
| 14 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +See the License for the specific language governing permissions and |
| 17 | +limitations under the License. |
| 18 | +
|
| 19 | +--> |
| 20 | + |
| 21 | +# nested2objects |
| 22 | + |
| 23 | +> Convert nested arrays to objects. |
| 24 | +
|
| 25 | +<section class="usage"> |
| 26 | + |
| 27 | +## Usage |
| 28 | + |
| 29 | +```javascript |
| 30 | +var nested2objects = require( '@stdlib/array/base/nested2objects' ); |
| 31 | +``` |
| 32 | + |
| 33 | +#### nested2objects( arr, fields ) |
| 34 | + |
| 35 | +Converts each nested array to an object. |
| 36 | + |
| 37 | +```javascript |
| 38 | +var x = [ [ 1, 2 ], [ 3, 4 ] ]; |
| 39 | + |
| 40 | +var fields = [ 'x', 'y' ]; |
| 41 | + |
| 42 | +var out = nested2objects( x, fields ); |
| 43 | +// returns [ { 'x': 1, 'y': 2 }, { 'x': 3, 'y': 4 } ] |
| 44 | +``` |
| 45 | + |
| 46 | +The function supports the following parameters: |
| 47 | + |
| 48 | +- **arr**: input array containing nested arrays. |
| 49 | +- **fields**: list of field names. |
| 50 | + |
| 51 | +</section> |
| 52 | + |
| 53 | +<!-- /.usage --> |
| 54 | + |
| 55 | +<section class="notes"> |
| 56 | + |
| 57 | +- The function assumes that all nested arrays have the same length. |
| 58 | +- The number of provided array labels should equal the length of each nested array. |
| 59 | + |
| 60 | +</section> |
| 61 | + |
| 62 | +<!-- /.notes --> |
| 63 | + |
| 64 | +<section class="examples"> |
| 65 | + |
| 66 | +## Examples |
| 67 | + |
| 68 | +<!-- eslint no-undef: "error" --> |
| 69 | + |
| 70 | +```javascript |
| 71 | +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; |
| 72 | +var filled2dBy = require( '@stdlib/array/base/filled2d-by' ); |
| 73 | +var nested2objects = require( '@stdlib/array/base/nested2objects' ); |
| 74 | + |
| 75 | +var x = filled2dBy( [ 10, 2 ], discreteUniform( -100, 100 ) ); |
| 76 | +var fields = [ 'x', 'y' ]; |
| 77 | + |
| 78 | +var out = nested2objects( x, fields ); |
| 79 | +// returns [...] |
| 80 | +``` |
| 81 | + |
| 82 | +</section> |
| 83 | + |
| 84 | +<!-- /.examples --> |
| 85 | + |
| 86 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 87 | + |
| 88 | +<section class="related"> |
| 89 | + |
| 90 | +</section> |
| 91 | + |
| 92 | +<!-- /.related --> |
| 93 | + |
| 94 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 95 | + |
| 96 | +<section class="links"> |
| 97 | + |
| 98 | +</section> |
| 99 | + |
| 100 | +<!-- /.links --> |
0 commit comments