I currently have a jQuery script that matches the values from my table to an array to find a corresponding url and output it as html. It works fine however I would like to keep my array private (so that all of the data cannot be viewed in the inspector if a match isn't found) and from my understanding that cannot be done with javascript. I am already using PHP to dynamically create the table so I was wondering whether this would be possible.
var profiles = [{
"name": "Susie",
"link": "www.google.com"
},
{
"name": "John",
"link": "www.yahoo.com"
}
];
$(document).ready(function() {
$('tr').each(function(index, item) {
var value = $(item).find('td').eq(1).text();
var exist = profiles.filter(c => c.name == value);
if (exist.length > 0) {
var link = exist[0].link;
$(item).find('td').eq(1).html("<a href='" + link + "'>" + value + "</a>");
}
})
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table>
<thead>
<th>#</th>
<th>Name</th>
</thead>
<tbody>
<tr>
<td>1
<td>Susie</td>
</tr>
<tr>
<td>2
<td>John</td>
</tr>
</tbody>
I was thinking of using a JSON file to store the data but I am not sure where to go from there.
$data = '{"Susie": "www.google.com","John": "www.yahoo.com"}';
$array = json_decode($somedata, TRUE);
</div>