Array.isArray()

In this example below you will see how to do a Array.isArray() with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by bretteast, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright bretteast ©

Technologies

  • HTML
  • CSS
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>Array.isArray()</title>
  
  
  <link rel='stylesheet prefetch' href='http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css'>

      <link rel="stylesheet" href="css/style.css">

  
</head>

<body>

  <div class="container">
  <h1>Array.isArray()</h1>
  <h2>Overview</h2>
  <p>This returns a true of false value depending on whether the argument passed in is an array or not.</p>
  <h2>Syntax</h2>
  <code>Array.isArray(obj)</code>
  <h2>Parameters</h2>
  <p>Pass is one argument in any format and the method will tell you if it is an array.</p>
  <h2>Examples</h2>
  <p>Thanks to MDN for the following examples</p>
  
  <p><code>Array.isArray([]);</code> returns <code id="output1"></code></p>
  <p><code>Array.isArray([1]);</code> returns <code id="output2"></code></p>
  <p><code>Array.isArray(new Array());</code> returns <code id="output3"></code></p>
    <p>Little known fact: Array.prototype itself is an array:</p>
  <p><code>Array.isArray(Array.prototype);</code> returns <code id="output4"></code></p>

  <p>All following calls return false</p>
  <p><code>Array.isArray();</code> returns <code id="output5"></code></p>
  <p><code>Array.isArray({});</code> returns <code id="output6"></code></p>
  <p><code>Array.isArray(null);</code> returns <code id="output7"></code></p>
  <p><code>Array.isArray(undefined);</code> returns <code id="output8"></code></p>
  <p><code>Array.isArray(17);</code> returns <code id="output9"></code></p>
  <p><code>Array.isArray('Array');</code> returns <code id="output10"></code></p>
  <p><code>Array.isArray(true);</code> returns <code id="output11"></code></p>
  <p><code>Array.isArray(false);</code> returns <code id="output12"></code></p>
  <p><code>Array.isArray({ __proto__: Array.prototype });</code> returns <code id="output13"></code></p>

  <h2>Try for yourself</h2>
  <p><code>Array.isArray(</code><input id="tryOutput" type="text"><code>);</code> returns <code></code></p>
  
</div>
  <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src='http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js'></script>

  

    <script  src="js/index.js"></script>




</body>

</html>

/*Downloaded from https://www.codeseek.co/bretteast/arrayisarray-YNbLWY */
body {
  font-family: sans-serif;
  background-color: #1d1f20;
  color: #fff;
  font-size: 1.6em;
  margin-left: 24px;
}

p {
  margin-bottom: 12px;
  color: #fff;
}


/*Downloaded from https://www.codeseek.co/bretteast/arrayisarray-YNbLWY */
$('#output1').html(Array.isArray([]).toString());
$('#output2').html(Array.isArray([1]).toString());
$('#output3').html(Array.isArray(new Array()).toString());
// Little known fact: Array.prototype itself is an array:
$('#output4').html(Array.isArray(Array.prototype).toString());

// all following calls return false
$('#output5').html(Array.isArray().toString());
$('#output6').html(Array.isArray({}).toString());
$('#output7').html(Array.isArray(null).toString());
$('#output8').html(Array.isArray(undefined).toString());
$('#output9').html(Array.isArray(17).toString());
$('#output10').html(Array.isArray('Array').toString());
$('#output11').html(Array.isArray(true).toString());
$('#output12').html(Array.isArray(false).toString());
$('#output13').html(Array.isArray({ __proto__: Array.prototype }).toString());

Comments