簡體   English   中英

數組名實例數組; 沒有按預期工作

[英]arrayname instanceof Array; isn't working as expected

我期待諸如“154, 544 true”之類的東西,但這不起作用。

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

<script>
  var n = [154, 45, 100, 544, 75], txt = "";
  var nFil = n.filter((value) => value > 100);
  txt = nFil.join(", ") + "<br>" + nFil instanceof Array;
  document.getElementById("demo").innerHTML = txt;
</script>

需要一個括號,如:

txt = nFil.join(", ") + "<br>" + (nFil instanceof Array);

我假設您要檢查變量是否為數組?

如果是,你可以使用這個

Array.isArray(<variable_name>); // returns `true` if the variable is an Array, `false` otherwise

完整參考: MDN

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM