Initialize cnt variable for assigning unique value to prime and its multiples
let cnt = 0 ; let prime = new Array ( n + 1 ) ; for ( let i = 0 ; i <= n ; i ++ ) prime [ i ] = 0 ; for ( let i = 2 ; i <= n ; i ++ ) {