Writing certain values of an array into a different array

I’ve got an array with multiple numbers in it, and i want to take every 15th value in this array and copy it into a different array.

is that possible(preferably without a loop)?

It’s certainly possible, but I don’t know how I would do it without a loop, I’m afraid. A loop is the most elegant way traverse arrays.

I would do something like this:

public string[] TakeEvery15th(string[] source)
{
    string[] every15th = new string[source.Length / 15];

    for (int i = 15, j = 0; i < source.Length; i += 15, j++)
    {
        every15th[j] = source*;*

}
return every15th;
}
Notice in particular the double counters inside the for-loop. The variable i causes the counter to jump 15 steps at a time in the source array, while the variable j sticks those values in 0, 1, 2… in the destination array.

Something like this should work if you need it in javascript

// assume "source" exists, and is your original array
// "dest" will be your new array.

var dest = [];
var numItems = Math.floor(source.length / 15);

for (var i = 0; i < numItems; ++i) {
    dest.push(source[i * 15]);
}

Spam - Removed by Almo