I have a loop to retrieve all users with the specific meta_key user values from wp_user_meta database and then put it in wp_localize_script array so I could access the data with Javascript and do my thing with it. Unfortunately, when I run the loop and put all the results to the variable, and try to console.log the results, I get just the string "Array" out in the console 3 times in one line, instead of the real values.
Here is my code:
functions.php
add_action('wp_enqueue_scripts','Load_Template_Scripts_wpa83855');
function Load_Template_Scripts_wpa83855(){
$args = array(
'meta_key' => 'quiz_scores'
);
$users = get_users($args);
foreach($users as $user){
echo "<pre>";
print_r(get_user_meta ($user->ID));
$veik .= get_user_meta ($user->ID);
echo "</pre>";
}
if ( is_page_template('page-quiz.php') ) {
wp_enqueue_script( 'quiz', get_template_directory_uri() . '/js/script.js', array(), '20151215', true );
wp_localize_script('quiz', Questions_list, array(
'siteUrl' => get_option("question"),
"ans" => get_option("answer"),
'ajax_url' => admin_url( 'admin-ajax.php' ),
'usr_scr' => $veik
));
}
}
print_r(get_user_meta ($user->ID)); works just fine, I get my all 3 users printed out with the meta_key "quiz_scores". But when I put it in the variable and then use it inside script localize like this: 'usr_scr' => $veik and try to console.log it in my other script.js file console.log(Questions_list.usr_scr); like I said, I get only string "Array" out in the console 3 times (as many times as there is users in database with that specific meta_key instead of the real value). I tried using toString() but it doesn't do anything. Any ideas?

.=is a string operator, you can't use it to append arrays.$veik .= get_user_meta ($user->ID);but same problem