I have an EJS array of String that I want to pass to a jquery function through data attribute. This is how I am passing it:
<td colspan="1" align="left" class="openModal" data-toggle="modal" data-target="#exampleModal"
data-reason=<%= systemp[i].REASON %> > click here </td>
Below function is invoked when click here is clicked and the data attribute is passed:
$('.openModal').click(function(){
var reason=$(this).data('reason');
//what to write here
for(let i=0;i<reason.length;++i)
console.log(reason[i]);
})
Suppose REASON array contains this: ["My","Name","is","XYZ"]. The output on console is this:
M
y
N
.
.
.
I want each element of the array to be printed on each line.
I tried to do the split on REASON array like this: reason=reason.split(",");, but it threw an error that split is not a function.
So how can I correctly pass an ejs array through data attribute and parse it corectly?
Any help is much appreciated. Thanks!