DEV Community

Discussion on: How not to sort an array in JavaScript

Collapse
 
damon profile image
damon

That's because the console.log returns undefined, and it's being used in the call to .map().

var array = [9, 2, 3, 8, 1, 0]
var orderedArray = [...array].sort()

console.log(array)
// [9, 2, 3, 8, 1, 0]
console.log(orderedArray)
// [0, 1, 2, 3, 8, 9]

var logReturn = console.log("hello world")
// hello world
console.log(logReturn)
// undefined
Thread Thread
 
zhuangya profile image
zhuangya

exactly, my point is we should not use map here at all.