Pig Latin need help

Tell us what’s happening:
I’m not able to join the entire array elements of arr
console.log(arr.join("")); // returns onsonantk,l,c,a,y not “onsonantklcay”

Your code so far


function translatePigLatin(str) {
  let arr = str.split("");
  if(/^[aeiou]/.test(str)){
     arr.push(...'way');
  }
  // console.log(str.match(/\w*?[aeiou]/));
 let temp = str.match(/\w*?[aeiou]/).toString();
//  console.log(temp.toString());
 temp=temp.split("");
 temp.pop();
//  console.log(temp);
  if(str.match(/\w*?[aeiou]/)){
      arr.push([temp,..."ay"]);
      let i=0;
      while(i<temp.length){
      arr.shift();
      i++;
      }
      console.log(arr.join(""));
  }
 console.log(arr);
 return arr.join("");
}

translatePigLatin("klconsonant");

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/pig-latin

You are creating a multidimensional array, your last console log is printing on the console the array below, and using join() the subarray is coerced to string before being added - an array coerced to string appear with its elements separated by commas

[ 'o',
  'n',
  's',
  'o',
  'n',
  'a',
  'n',
  't',
  [ [ 'k', 'l', 'c' ], 'a', 'y' ] ]

Ahaaann!!!
Got it…
Thanks for the quick response :heart_eyes: