javascript - Indexing an array by a quotient -
in following code, i
number quotient i / 2
should integer. should still use math.floor(i / 2)
on safe side? i'm asking because javascript treat numbers floating points i'm concerned rounding errors.
for (var = 0; < data.length; = + 2) { var name = names[i / 2]; ... }
no. not have use math.floor()
in situation.
because i
, names[1.00]
equivalent names[1]
.
to check, try below in javascript console.
the length of array 20 , first 10 array items printed
var names = ["nums1", "nums2", "nums3","nums4", "nums5", "nums6","nums7", "nums8", "nums9","nums10", "nums11","nums12", "nums13","nums14", "nums15", "nums16","nums17", "nums18", "nums19","nums20"]; (var = 0; < names.length; = + 2) { console.log(names[i/2]); }
Comments
Post a Comment