0

I was expecting something like "154, 544 true" but this is not working.

<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>
  • 2
    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence – John Montgomery Jan 15 '20 at 01:04
  • As noted below, [`Array.isArray()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray) is the way to test for an Array. See https://stackoverflow.com/questions/22289727/difference-between-using-array-isarray-and-instanceof-array – spender Jan 15 '20 at 01:35

2 Answers2

1

A parentheses needed like:

txt = nFil.join(", ") + "<br>" + (nFil instanceof Array);
Yonggoo Noh
  • 1,811
  • 3
  • 22
  • 37
0

I assume that you want to check a variable is an Array or not?

If yes, you can use this

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

Complete reference: MDN