I have an array that looks like this
array_names = [Mathew,Kelp ,Liman Kolf, Hebert,Ansh];
Now in the array above, Mathew, Kelp is one name , Liman Kolf is another name and Herbet,Ansh is another name making it 3 names in the array.
Now i want to split this array on new lines in table like below
Mathew,Kelp
Liman Kolf
Herbet,Ansh
But with my code as shown below, the table is represented like this
Mathew
Kelp
Liman Kolf
Herbet
Ansh
JS
//how i save to localstorage
$("#myTableID").on("click", "#add-contact", function() {
var values = [];
value = jQuery(this).closest('tr').find('#user-id').text();
values.push(value);
localStorage.setItem('contact_list', values);
}
var array_names = localStorage.getItem('contact_list').split(',');
if(array_names.length)
{
$.each(array_names, function(index, value){
$('#myTableID2').append('<tr><td id="contact">'+value+'</td></tr>');
});
}
Controller
$contacts = Contact::where('firstname','LIKE','%'.$q.'%')->orWhere('lastname','LIKE','%'.$q.'%')->get();
,in between both of the items["Mathew,Kelp", "Liman Kolf", "Hebert,Ansh"]. Otherwise, there's no way to tell if the,is the separator or part of the name.JSON.stringifywhen storing the values array andJSON.parsewhen retrieving it. Or, at the very least, do avalues.join(';')so that you can split it later on semicolons.