One of the problems in your example is that multiple elements have the same id
Unfortunately, this is not possible with HTML and I suggest you make them classes first.
As for your question, it's possible but you would have to do it like so:
$(function () {
  $(".element").each(function () {
     const arr = $(this).data('array');
     let text = 'Does not include 2';
 
     
     if (arr.includes(2)) {
         text = 'Does include 2';       
     }
     
     $(this).text(text);
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="element" data-array="[1,2,3,4]"></div>
<div class="element" data-array="[5,6,7]"></div>
<div class="element" data-array="[2,3]"></div>
 
 
If you don't want to find by class, you can also search by the data attribute, and then use the same code from above to check for presence of a value in the array:
$("[data-array]").each(...)