# Repeat a function in Javascript with .length

I have a long string.

```var string = "This is a long string."
```

```downloadfunction{... 'echo "'+string+'" >> '+path;}
```

How do I execute this function for every 2 letters of the string? Read somewhere about using ".length" but not sure how to implement it in this case. I also do not want to split the string into an array. The download function should help split the string to download 2 letters progressively.

I.e. I would like to download the string 2 letters at a time.

EDIT: To clarify, the string needs to be downloaded x characters at a time as the download would break if it exceeds that limit.

Here is an example that is commented on how to do this:

```var string = 'a really really really long string \
that I want to split by two letters at a time';

// this needs to be ceiling so that it always rounds up on odd numbers
// otherwise the last letter may be left out
var iterations = Math.ceil(string.length / 2);

for (var i = 0; i < iterations; i++) {

// we are iterating over half of the length but want to go two letters at a time
var j = i*2;

// make a new string with the first letter
var letters = string[j]

// this is an if statement to check if there is a second letter
// if there is concat it to the first letter
// otherwise the last set of an odd length would concat `undefined` to it
if (string[j+1]) { letters += string[j+1]; }

// call your function here passing `letters` to it
}
```

count string length divide by 2 round up or down what ever you like

then do a for loop of the amount after the devision.

Somethig like this

```//Your string that is downloaded
var string = "This is a long string."

//calculate the amount of character in the string
var amount = string.length;

//divide the string by 2
var roundnr = amount/2;

for (var i=0;i<Math.round(roundnr);i++)
{
//do something here for every 2 characters in the string
}
```