DEV Community

Discussion on: JavaScript Array methods

Collapse
 
someshium profile image
someshium

I am not getting how the sort function adds the elements to a new array based on return value 1 or -1. Can you please explain this?

Collapse
 
shreyazz profile image
Shreyas Pahune

That is how the sort function is made...you just have to give it a variable, and if the values matches then it will get pushed into the new variable we created.