Good day.

I have such a problem, I can not connect (glue) the elements of the array into one line, here is the code:

function rt() { var first = []; // создаем массив символов var stroka = ""; // создаем конечную строку $('.sch').append($(this).val()); // после класса выводим на экран по 1 символу first[l] = $(this).val(); // заносим каждый символ в массив stroka += '' + first[l] + ''; // теперь надо составить одну строку символов l++; // увеличиваем индекс массива alert(stroka); // выдача для проверки, **выдает только последний символ** return stroka; // ну и возврат } 

Help me please. :)

  • four
    odd odd code ['h', 'e', ​​'l', 'l', 'o', ',', '', 'w', 'o', 'r', 'l', 'd' ] .join (""); - join - Specter
  • 2
    Well, or cycle. join of course yes, in short) - Shevsky
  • Well this is for my case it should be so) - Bob Marley
  • 2
    Does your case necessarily require an Indocode? - Specter
  • one
    You have described the task in a completely different way that your code "must perform" it. - Blah blah blah, I need to output on alert the sum of the first and second digits from the minutes of the current date, I have the code, but for some reason it returns an incorrect value: alert (((minute [1] + minute [2] ) / sqrt (hour * rand (1, 5)) + (rand (1, 2) == 1? 10: sqr (rand (10, 50)))); - Why does it divide by an hour multiplied by a random number and a bunch of strange operations? - For my case it is necessary. - Shevsky

2 answers 2

Hmmm .. A lot of things will remain a mystery to me, but, although I’m not a telepath, I’ll still try)) Look at this example , it may be useful.

    You probably just need to initialize the variable l. If you look at this example , you can see that without initialization, l always NaN or undifended which leads to writing in first[NaN] .

    although in your case there is some discrepancy between the code and the question as well as the array - why is it needed at all? Your code is similar to this:

     function rt() { var chren = ""+$(this).val()+""; $('.sch').append(chren); // добавляем хрень в контейнеры с классом .sch alert(chren); // выдача для проверки, **выдает только последний символ** return chren; // ну и возврат } 
    • one
      @denisKlimenko, as part of the question, edit it so that it clearly describes your task and your difficulties. I doubt that you want to pay me my time, communicating not within the framework of the hashcode :-) - Chad
    • Uncle - Khokhol? It can be seen :-) - Chad