I am trying to take an array of strings from a PHP file so that I can use it within my javascript file. I was able to get access to it ($namelist) in my javascript, but whenever I try to print it, the strings in the array get printed out as separate letters, like as if each letter of each word was given its own index.
I do not want this. I want to print the entire word on a single line. In this model, there should only be two words printed out. (hakim and henry)
var letters = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"];
const dir = "./submissions/";
// const fs = require('fs');
var extensions = [".jpg",".png"];
    for( var i = 0; i < letters.length;i++){
      var node = document.createElement("li");
      var button = document.createElement("input");
      var textnode = document.createTextNode(letters[i]);
      button.type = "button";
      button.className = letters[i];
      button.value = letters[i];
      button.setAttribute('onclick',"thisfunction(this,'one')");
      button.appendChild(textnode);
      node.appendChild(button);
      document.getElementById('letters').appendChild(node);
    }
    function thisfunction(obj,abc){
      var letterclass = obj.className;
      $.post('php/loadnames.php',{postname:letterclass},
      function(data){
        for(const child of data){
          var node = document.createElement("li");
          var link = document.createElement("a");
          var textnode = document.createTextNode(child);
          link.href = '#';
          link.appendChild(textnode);
          node.appendChild(link);
          document.getElementById('buddy_load').appendChild(node);
        }
PHP/loadnames:
<?php
$namelist = array();
$name = $_POST['postname'];
$path = '../submissions';
$files=scandir($path);
foreach($files as &$value){
  if(strtolower(substr($value,0,1)) == strtolower($name)){
    array_push($namelist, strtolower(strtok($value,'_')));
  }
  // echo strtolower(substr($value,0,1));
}
$namelist = array_unique($namelist);
// echo count($namelist);
// $namelist = sort($namelist);
$keys = implode($namelist );
  // echo implode(',',$namelist);
  echo $keys;
?>

 
    