File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ smart people at [Hashrocket](http://hashrocket.com/).
1010For a steady stream of TILs from a variety of rocketeers, checkout
1111[ til.hashrocket.com] ( https://til.hashrocket.com/ ) .
1212
13- _ 669 TILs and counting..._
13+ _ 670 TILs and counting..._
1414
1515---
1616
@@ -227,6 +227,7 @@ _669 TILs and counting..._
227227
228228- [ Accessing Arguments To A Function] ( javascript/accessing-arguments-to-a-function.md )
229229- [ Character Codes from Keyboard Listeners] ( javascript/character-codes-from-keyboard-listeners.md )
230+ - [ Check If Something Is An Array] ( javascript/check-if-something-is-an-array.md )
230231- [ Computed Property Names In ES6] ( javascript/computed-property-names-in-es6.md )
231232- [ Create An Array Containing 1 To N] ( javascript/create-an-array-containing-1-to-n.md )
232233- [ Create Bootstrapped Apps With Yarn] ( javascript/create-bootstrapped-apps-with-yarn.md )
Original file line number Diff line number Diff line change 1+ # Check If Something Is An Array
2+
3+ The ` Array ` class has a function on it called
4+ [ ` isArray() ` ] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray )
5+ which can be used to check if something is an array.
6+
7+ ``` javascript
8+ > Array .isArray (' Hello, World!' );
9+ // => false
10+
11+ > Array .isArray ([' One' , 2 , [3 ]]);
12+ // => true
13+
14+ > Array .isArray ({ foo: ' bar' });
15+ // => false
16+
17+ > Array .isArray ([]);
18+ // => true
19+ ```
20+
21+ The MDN docs provide an [ example
22+ polyfill] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray#Polyfill )
23+ if it is not natively available.
24+
25+ ``` javascript
26+ if (! Array .isArray ) {
27+ Array .isArray = function (arg ) {
28+ return Object .prototype .toString .call (arg) === ' [object Array]' ;
29+ };
30+ }
31+ ```
You can’t perform that action at this time.
0 commit comments