README.md (2179B)
1 <!-- 2 3 @license Apache-2.0 4 5 Copyright (c) 2019 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 # Non-Index Keys 22 23 > Return an array of an object's own enumerable property names which are not integer indices. 24 25 <section class="usage"> 26 27 ## Usage 28 29 ```javascript 30 var nonIndexKeys = require( '@stdlib/utils/nonindex-keys' ); 31 ``` 32 33 #### nonIndexKeys( obj ) 34 35 Returns an `array` of an object's own enumerable property names which are not integer indices. 36 37 ```javascript 38 var arr = [ 1, 2, 3 ]; 39 arr.a = 'foo'; 40 arr.b = 'bar'; 41 42 var keys = nonIndexKeys( arr ); 43 // e.g., returns [ 'a', 'b' ] 44 ``` 45 46 </section> 47 48 <!-- /.usage --> 49 50 <section class="notes"> 51 52 ## Notes 53 54 - Name order is not guaranteed, as `object` key enumeration is not specified according to the [ECMAScript specification][ecma-262-for-in]. In practice, however, most engines use insertion order to sort an `object`'s keys, thus allowing for deterministic extraction. 55 - In contrast to the built-in `Object.keys()`, if provided `null` or `undefined`, the function returns an empty `array`, rather than throwing an error. 56 57 </section> 58 59 <!-- /.notes --> 60 61 <section class="examples"> 62 63 ## Examples 64 65 <!-- eslint no-undef: "error" --> 66 67 ```javascript 68 var nonIndexKeys = require( '@stdlib/utils/nonindex-keys' ); 69 70 function Foo() { 71 this[ 0 ] = 3.14; 72 this.beep = 'boop'; 73 this.a = { 74 'b': 'c' 75 }; 76 return this; 77 } 78 79 Foo.prototype.foo = [ 'bar' ]; 80 81 var obj = new Foo(); 82 var keys = nonIndexKeys( obj ); 83 84 console.log( keys ); 85 // e.g., => [ 'beep', 'a' ] 86 ``` 87 88 </section> 89 90 <!-- /.examples --> 91 92 <section class="links"> 93 94 [ecma-262-for-in]: http://www.ecma-international.org/ecma-262/5.1/#sec-12.6.4 95 96 </section> 97 98 <!-- /.links -->