0

Considering the below code snippet, obj[arr[i]] = arr[i] storing key,values in accending sorted order by default.

 var arr = [100,2,55,4,3,5,2,66]
    var obj = {}
    for(let i in arr)
      {
        obj[arr[i]] = arr[i] 
      }
    
    console.log(Object.values(obj)) // output : [2, 3, 4, 5, 55, 66, 100]

I am trying to know the reason behind it, is it the default nature of objects in javascript?

if am not wrong this would be the simplest O(n) time complexity sorting algorithm if the array is non-duplicate numbers

Yusuf Khan
  • 1,852
  • 1
  • 19
  • 26

0 Answers0