<?php
$pass = [];
$array = [
"name" => "value",
"anotherName" => "anotherValue"
];
foreach($array as $key => $value){
if (array_key_exists($key, $pass)) {
$pass[$key] = array_merge_recursive($pass[$key], $value);
} else {
$pass[$key] = $value;
}
}
?>
<html>
<head>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script>
const variable = $.extend({}, <?= json_encode($pass) ?> );
$(function(){
$(".result").html(variable.anotherName);
});
</script>
</head>
<body>
<div class="result"></div>
</body>
</html>