Sorting in Javascript array

<button onclick="sortArray()">Sort Array</button>

<p id="demo"></p>

<script>
var courses = ["javascript", "php", "angularjs", "node js"];
document.getElementById("demo").innerHTML = courses;
function sortArray() {
courses.sort();
document.getElementById("demo").innerHTML = courses;
}
</script>

Share This:

Leave a Reply

Your email address will not be published. Required fields are marked *