View Full Version : How to get a constant variable of array

06-16-2009, 08:33 AM
hi i hav an array named contents [i] where i wanna get every 3rd value out of it.below i make an example:

contents [i] = [2,4,6,8,10,12,14,16,18];

i wanna find a script dat could return every third value which is 3,6,9
so any1 noe how to do it? thanks

Philip M
06-16-2009, 09:49 AM
Try this:-

<script type = "text/javascript">
var contents = [2,4,6,8,10,12,14,16,18,21];
var result = [];
var count = 0;
for (var i = 2; i<contents.length; i= i+3) {
result[count] = contents[i];

alert (result); // 6,12,18

"Funding is to be cut for sports where targets have been missed, such as archery". - Government circular