[英]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.