javascript - Splice function to get rid of 6/7th of the entries in an array -


i'm trying understand i'm going wrong here. have array:

result = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]       

i want rid of every 6 entries in array, leave 7th there, , go one. in effect i'm hoping rid of 6/7th of values in array. i'm thinking splice() perfect that, somehow code below doesn't seem work. suggestions?

many all!

function random_select ()     {       for(var i=0; < result.length; i+7)       {         result.splice[i,6];        }     }; 

try instead:

var result = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]; (var = 0; < result.length; i++) result.splice(i, 6); 

this will:

  1. first remove [0, 1, 2, 3, 4, 5], , let [6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16] be.
  2. next remove [7, 8, 9, 10, 11, 12] , let [13, 14, 15, 16] be.
  3. finally remove [13, 14, 15, 16].

hence result [6, 13]. want?


Comments