I have been struggling with this for the last two hours and still can not find a solution (maybe I am blocked!!).
I will start with how the result/output should looks like and is as follow:
results = [
'result_1' => [
"col_1" => "asc",
"col_2" => "asc",
"col_3" => "asc"
]
];
This is how I am doing it so far:
var ls_sort_keys = [];
var ls_settings = {};
var ls_report_name = "<?php echo $report_name ?>";
<?php foreach ($header_array as $key => $value) { ?>
ls_sort_keys.push("<?php echo $value; ?>");
<?php } ?>
ls_settings[ls_report_name] = {
$.each(ls_sort_keys, function (key, value) {
console.log(key, value);
});
}
The result of console.log(ls_sort_keys) is an array of three values containing ["col_1", "col_2", "col_3"].
I am getting the following error Uncaught SyntaxError: Unexpected token . in this line $.each(ls_sort_keys, function (key, value) and my guess is because is not allowed such thing in there.
Having said that, how I can transform the result into the output? The output is shown as an array but could be a Javascript object since it will be stored in the localStorage and AFAIK it does not support array but only strings.
push(). (Except that last one){ items: $.each(...) }console.logoutputs something when you also say you have a syntax error. It cannot be both. This question lacks information needed to reproduce the issue.console.log(ls_sort_keys)I am able to see an array of three elements which is the expected result there. I am not following you.