|
| 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 | +# anyHasOwnProp |
| 22 | + |
| 23 | +> Test whether at least one element in a provided array has a specified own property. |
| 24 | +
|
| 25 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> |
| 26 | + |
| 27 | +<section class="intro"> |
| 28 | + |
| 29 | +</section> |
| 30 | + |
| 31 | +<!-- /.intro --> |
| 32 | + |
| 33 | +<!-- Package usage documentation. --> |
| 34 | + |
| 35 | +<section class="usage"> |
| 36 | + |
| 37 | +## Usage |
| 38 | + |
| 39 | +```javascript |
| 40 | +var anyHasOwnProp = require( '@stdlib/array/base/assert/any-has-own-property' ); |
| 41 | +``` |
| 42 | + |
| 43 | +#### anyHasOwnProp( arr, property ) |
| 44 | + |
| 45 | +Tests whether at least one element in a provided array has a specified own property. |
| 46 | + |
| 47 | +```javascript |
| 48 | +var o1 = { |
| 49 | + 'a': 1 |
| 50 | +}; |
| 51 | +var o2 = { |
| 52 | + 'b': 2 |
| 53 | +}; |
| 54 | +var o3 = { |
| 55 | + 'c': 3 |
| 56 | +}; |
| 57 | + |
| 58 | +var bool = anyHasOwnProp( [ o1, o2, o3 ], 'b' ); |
| 59 | +// returns true |
| 60 | + |
| 61 | +bool = anyHasOwnProp( [ o1, o2, o3 ], 'd' ); |
| 62 | +// returns false |
| 63 | + |
| 64 | +bool = anyHasOwnProp( [ o1, o2, o3 ], 'toString' ); |
| 65 | +// returns false |
| 66 | +``` |
| 67 | + |
| 68 | +</section> |
| 69 | + |
| 70 | +<!-- /.usage --> |
| 71 | + |
| 72 | +<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 73 | + |
| 74 | +<section class="notes"> |
| 75 | + |
| 76 | +</section> |
| 77 | + |
| 78 | +<!-- /.notes --> |
| 79 | + |
| 80 | +<!-- Package usage examples. --> |
| 81 | + |
| 82 | +<section class="examples"> |
| 83 | + |
| 84 | +## Examples |
| 85 | + |
| 86 | +<!-- eslint no-undef: "error" --> |
| 87 | + |
| 88 | +```javascript |
| 89 | +var fromCodePoint = require( '@stdlib/string/from-code-point' ); |
| 90 | +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); |
| 91 | +var filledBy = require( '@stdlib/array/filled-by' ); |
| 92 | +var anyHasOwnProp = require( '@stdlib/array/base/assert/any-has-own-property' ); |
| 93 | + |
| 94 | +function randomObject() { |
| 95 | + var o = {}; |
| 96 | + o[ fromCodePoint( 97+discreteUniform( 0, 25 ) ) ] = 0; |
| 97 | + return o; |
| 98 | +} |
| 99 | + |
| 100 | +var arr = filledBy( 10, 'generic', randomObject ); |
| 101 | +console.log( arr ); |
| 102 | + |
| 103 | +var bool = anyHasOwnProp( arr, 'a' ); |
| 104 | +console.log( 'a: %s', bool ); |
| 105 | + |
| 106 | +bool = anyHasOwnProp( arr, 'b' ); |
| 107 | +console.log( 'b: %s', bool ); |
| 108 | +``` |
| 109 | + |
| 110 | +</section> |
| 111 | + |
| 112 | +<!-- /.examples --> |
| 113 | + |
| 114 | +<!-- 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. --> |
| 115 | + |
| 116 | +<section class="references"> |
| 117 | + |
| 118 | +</section> |
| 119 | + |
| 120 | +<!-- /.references --> |
| 121 | + |
| 122 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 123 | + |
| 124 | +<section class="related"> |
| 125 | + |
| 126 | +</section> |
| 127 | + |
| 128 | +<!-- /.related --> |
| 129 | + |
| 130 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 131 | + |
| 132 | +<section class="links"> |
| 133 | + |
| 134 | +</section> |
| 135 | + |
| 136 | +<!-- /.links --> |
0 commit comments