0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

javaScript_constructorメソッドを使って、DateやArrayの判別

Posted at
<body>
 <p id="test1"></p>
 <p id="test2"></p>
 <script>
  var dateTest = new Date();
  var arrayTest = ["i","am","array"];
  var pTest1 = document.getElementById("test1");
  var pTest2 = document.getElementById("test2");
  pTest1.innerHTML = isDate(dateTest);
  pTest2.innerHTML = isArray(arrayTest);

  // Date判別メソッド
  function isDate(date){
   var result = date.constructor.toString().indexOf("Date") > -1;
   return result;
  }

  // Array判別メソッド
  function isArray(array){
   var result = array.constructor.toString().indexOf("Array") > -1;
   return result;
  }
 </script>
</body>

// 結果
true
true
0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?