How do I go about converting an array with multiple strings to a single string using .join?

var ManyAnt =['ant 123,' 'ant 234', 'ant 345' 'ant456']

use arr.join(j)

where j is a string that refers to how you want the array elements to be joined, for example if you want to join them using spaces inbetween the elements

ManyAnt.join(' ') will do

How would you return this in a function?
I am required to turn something from a string, into an array, sort it, and return a number.
Here is my example:

var ManyAnt = 'ant 123, ant 234, don 123, ant 345, don 345,  ant 456'; 
function countAllFromAnt(antX) {
console.log(antX); //display the initial string (assuming this is running in the background)
  var afterForLoop = []; ///this is the output after the sorted ant list
 var stringOrig = antX.split(',_'); ///this is removing based on the commas and turning it into an array with many strings i.e. ['xxx', 'xxx']
  console.log(stringOrig);
  for (var i = 0; i <stringOrig.length;i++) { ///this is initiating the counter at position zero of the array and counting up until the length of the array is reached by one 
    if (stringOrig[i].startsWith(AntX)){ ///this sorts by Antxxx and turns it into list; I believe this is a string, a list.
  afterForLoop.push(stringOrig[i])   ///this is turning it into a string. I think this is incorrect, I want to count the item in the now sorted list that is pushed to afterForLoop.
                                       
  }
    
  } 


console.log (afterForLoop); //this shows what happens with afterForLoop
console.log (afterForLoop.join(''); this shows a string of the list we created and could be incorrect
 
 return afterForLoop.length //returns the amount of items in the final sorted array
///what do I return above?

assert.equal(antX);  ///confirms if the parameter output is what we expect

};

UPDATE 2: I have written pseudo-code for what happens at each step

I have explained above exactly what I want to do by using code instead of just describing.

Thats what I meant. I may have laid out the question wrong.
let me edit it

I have now updated the problem (the actual code).

Yes, I changed it now. Sorry for that basic syntax error. I did it before in my mind and not in practice haha

Im not sure my othe reply went through but I changed the syntax yes.

Yes I did that. I wrote it all out but I’m still getting used to the built in functions like.length in applied situations. I’m trying to return the number of antxxx

I have commented in my thought process.

Do you want me to post it seperately?

Heading out for a run, so it will be a few hours before I am back online. I have posted a possible solution below based on what I believe you want in case you do not figure it out on your own. Try not to look at it until you have solved it yourself.

var ManyAnt = 'ant 123, ant 234, ant 345, ant 456';
function countAllFromAnt(antX) {
  var counter = 0;
  var filteredArr = [];
  var arrWords = antX.split(', ');
  for (var i = 0; i <arrWords.length;i++) {
    if (arrWords[i].startsWith('ant')){
      filteredArr.push(arrWords[i]);
      counter++;                                   
    }
  } 
  console.log(filteredArr); // new array
  console.log(filteredArr.join(', ')); // string of array
  return counter;
}
countAllFromAnt(ManyAnt);

I changed the delimiter to be according to your specifications (also because I should have noticed that!)

Are you back, Randall Dawson?