Archive

Calender

«   2019/09   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30          
[ Javascript ] Array.isArray()


Polyfill

 
<script type="text/javascript">
/* 
 * source : 
 * https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray
 */ 
if ( ! Array.isArray ) { 
    Array.isArray = function isArray ( arg ) { 
        return Object.prototype.toString.call( arg ) === "[object Array]"; 
    }; 
} 
</script>
 


typeof

 
<button onclick="testing()"> Click me </button>

<p id="demo"> </p>

<script type="text/javascript">
function testing () { 

    var myArray = [ "A", "B", "C" ]; 

    var type = typeof myArray; 

    demo.innerHTML = type; 
} 
</script>
 


Object.prototype.toString

 
<button onclick="testing()"> Click me </button>

<p id="demo"> </p>

<script type="text/javascript">
function testing () { 

    var myArray = [ "A", "B", "C" ]; 

    var objToSting = Object.prototype.toString.call( myArray ); 

    demo.innerHTML = objToSting; 
} 
</script>
 


Array.isArray()

 
<button onclick="example()"> Click me </button>

<p id="demo"> </p>

<script type="text/javascript">
function example () { 

    var array = [ "A", "B", "C" ]; 

    demo.innerHTML = Array.isArray( array ); 
} 
</script>
 
 
<button onclick="example()"> Click me </button>

<p id="demo"> </p>

<script type="text/javascript">
function example () { 

    var string = "A, B, C"; 

    demo.innerHTML = Array.isArray( string ); 
} 
</script>
 
 
<button onclick="example()"> Click me </button>

<p id="demo"> </p>

<script type="text/javascript">
function example () { 

    var object = { 0: "A", 1: "B", 2: "C", length: 3 }; 

    demo.innerHTML = Array.isArray( object ); 
} 
</script>
 


이 내용이 도움이 되셨다면, 아래의 하트 버튼을 눌러주세요 *^^*
If this article is helpful to you, please click the heart button below. *^^*

0 Comments