answersLogoWhite

0


Best Answer

You have the sort() method of Javascript arrays:
---
var a = [1,2,10,11];
a.sort(); // gives [1, 10, 11, 2]
---
The default sort is lexicographic, sorting the values as strings.

For numbers and descending sort, you can pass in a function:
---
function sortNum(a, b) {
return a - b;
}
function sortDesc(a, b) {
return b - a;
}
a.sort(sortNum); // gives [1, 2, 10, 11]
a.sort(sortDesc); // gives [11, 10, 2, 1]
---
The function takes two arguments, and returns a negative number if the first element is smallest, a positive number if the first element is largest, and zero if they are equal.

See related link.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Ascending and descending order in HTML javascript?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What languages can a browser understand?

HTML, CSS, & JavaScript.


Can you make HTML dynamic website?

HTML is, by its very nature, static. In order to add dynamic elements, you will need to use JavaScript.


Do you have experience in Java or HTML?

I have some experience in HTML but not JavaScript.


Is the ePO console It is web based and designed completely in HTML and JavaScript.?

It is web-based and designed completely in HTML and JavaScript


How is javascript used?

JavaScript is used to make HTML DHTML or Dynamic HTML. Provides a lot more interactivity between the web page and the browser provided JavaScript is not turned off.

Related questions

What languages can a browser understand?

HTML, CSS, & JavaScript.


Why you use javascript with HTML?

JavaScript is a script which makes HTML more interactive and adds more functionality to HTML.


Can you make HTML dynamic website?

HTML is, by its very nature, static. In order to add dynamic elements, you will need to use JavaScript.


Is HTML a script language?

No, but you can nest JavaScript into the HTML.


What you need to study to create your website?

I would suggest you start with HTML and then move on to JavaScript VBScript would come after that. EX: <html><body><!--HTML HERE--> <!--JAVASCRIPT STARTS BELOW--> <script language="JavaScript"> //JAVASCRIPT HERE </script> <!--JAVASCRIPT ENDS HERE--> <!--VBSCRIPT STARTS BELOW--> <script language="VBScript"> 'VBSCRIPT HERE </script> </body></html>


Do you have experience in Java or HTML?

I have some experience in HTML but not JavaScript.


Is the ePO console It is web based and designed completely in HTML and JavaScript.?

It is web-based and designed completely in HTML and JavaScript


How do I make it so things switch order in HTML?

HTML does not have the ability to switch the order of elements after the page has loaded. You will need to use JavaScript or another scripting language. HTML is not a scripting language, it is a markup language.


Is javascript a form of HTML used to add dynamic capabilities and interactivity to webpages?

Javascript is a language used WITH HTML. It is not HTML. HTML is a markup language used to delineate between different types of data. JavaScript is a programming language, containing logic, functions, and object.


How is javascript used?

JavaScript is used to make HTML DHTML or Dynamic HTML. Provides a lot more interactivity between the web page and the browser provided JavaScript is not turned off.


How do you write HTML codes and javascript events together in your HTML kit?

You need to write the HTML code in the tag format. If you want to write JavaScript put it in <script> tag.


How do you create a simple JavaScript message inside the HTML?

You need to type the following code to create a simple JavaScript message inside the HTML