Quantcast
Channel: How do I check if an array includes a value in JavaScript? - Stack Overflow
Viewing all articles
Browse latest Browse all 66

Answer by rlib for How do I check if an array includes a value in JavaScript?

$
0
0

One can use Set that has the method "has()":

function contains(arr, obj) {
  var proxy = new Set(arr);
  if (proxy.has(obj))
    return true;
  else
    return false;
}

var arr = ['Happy', 'New', 'Year'];
console.log(contains(arr, 'Happy'));

Viewing all articles
Browse latest Browse all 66

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>