snipt

Ctrl+h for KB shortcuts

Text only

Javascript is Array

1
2
3
if( Object.prototype.toString.call( someVar ) === '[object Array]' ) {
    alert( 'Array!' );
}

Description

test object to see if an array
https://snipt.net/embed/92ee56a5905e75e07dd09d7011d99052/
/raw/92ee56a5905e75e07dd09d7011d99052/
92ee56a5905e75e07dd09d7011d99052
text
Text only
3
2019-07-15T18:44:54
True
False
False
Sep 09, 2013 at 06:36 PM
/api/public/snipt/79948/
javascript-is-array
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>if( Object.prototype.toString.call( someVar ) === &#39;[object Array]&#39; ) { </span><span id="L-2"><a name="L-2"></a> alert( &#39;Array!&#39; ); </span><span id="L-3"><a name="L-3"></a>} </span></pre></div> </td></tr></table>
array, javascript