Javascript for..in vs for loop performance

前端 未结 4 680
忘了有多久
忘了有多久 2020-11-30 11:36

I was clustering around 40000 points using kmean algorithm. In the first version of the program I wrote the euclidean distance function like this

var euclide         


        
4条回答
  •  被撕碎了的回忆
    2020-11-30 11:49

    The For/In loop, simply loops through all properties in an object. Since you are not specifying the number of iterations the loop needs to take, it simply 'guesses' at it, and continues on until there are no more objects.

    With the second loop, you are specifying all possible variable... a)a starting point, b) the number of iterations the loop should take before stopping, c) increasing the count of the starting point.

    You can think of it this way... For/In = guesses the number of iterations, For(a,b,c) you are specifying

提交回复
热议问题