dcsimg
www.webdeveloper.com
Results 1 to 3 of 3

Thread: Sorting Statement

  1. #1
    Join Date
    Oct 2003
    Location
    Pensacola, Fl
    Posts
    241

    Sorting Statement

    Hi everyone....I've used a sorting statement on my index page script, but there's something not right with it. When I take the sort statement out of my script, the script executes as expected. When I put the sort statement in the code, most everything runs as expected, but certain display images don't appear as expected. I'm generally just trying to sort an array before I use the elements to populate a list. If anyone can see that there's something wrong with how I've written it, let me know. I'd appreciate your input. Here's the statement:

    Code:
    Items.sort(function(a,b){a=a[4]; b=b[4]; return a<b?-1:1;});
    okham
    Your friendly neighborhood Okham. -o-o-

  2. #2
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    4,800
    you pass a simple function of
    Code:
     function(a,b){ return a-b;}
    Simpler to follow : http://www.w3schools.com/jsref/jsref_sort.asp
    More in depth : https://developer.mozilla.org/en/doc...cts/Array/sort
    --> JavaScript Frameworks like JQuery, Angular, Node <--
    ... and please remember to wrap code with forum BBCode tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

  3. #3
    Join Date
    Jan 2016
    Location
    Rajkot
    Posts
    2
    Quote Originally Posted by \\.\ View Post
    you pass a simple function of
    Code:
     function(a,b){ return a-b;}
    Simpler to follow : http://www.w3schools.com/jsref/jsref_sort.asp
    More in depth : https://developer.mozilla.org/en/doc...cts/Array/sort
    Thanks for valuable resource share with me, Easy set up ascending order value or variable help of sort () method.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles