JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 11th, 2008, 03:31 AM
Jason Knight Jason Knight is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Long Beach, CA
Posts: 117 Jason Knight User rank is Lance Corporal (50 - 100 Reputation Level)Jason Knight User rank is Lance Corporal (50 - 100 Reputation Level)Jason Knight User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 2 Days 6 h 46 m 33 sec
Reputation Power: 11
Sorting object array by property

I have an array of objects that I need to sort by their property xpos. I then need to set the zindex property of the object in order of xpos from lowest to highest.
I’m having some problems getting code to do this correctly. What approach can I take to do this?

Reply With Quote
  #2  
Old November 11th, 2008, 07:09 AM
Winters Winters is offline
Super Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jul 2003
Posts: 3,931 Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 2 Days 12 h 3 sec
Reputation Power: 2571
Post the array.
Comments on this post
vbrtrmn agrees: I concur, it is quite hard to debug problems w/o any data.
__________________
[PHP] | [Perl] | [Python] | [Java] != [JavaScript] | [XML] | [ANSI C] | [C++] | [LUA] | [MySQL] | [FirebirdSQL] | [PostgreSQL] | [HTML] | [XHTML] | [CSS]

W3Fools - A W3Schools Intervention.

Reply With Quote
  #3  
Old November 11th, 2008, 07:40 PM
Arty Effem's Avatar
Arty Effem Arty Effem is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2006
Location: England
Posts: 398 Arty Effem User rank is Second Lieutenant (5000 - 10000 Reputation Level)Arty Effem User rank is Second Lieutenant (5000 - 10000 Reputation Level)Arty Effem User rank is Second Lieutenant (5000 - 10000 Reputation Level)Arty Effem User rank is Second Lieutenant (5000 - 10000 Reputation Level)Arty Effem User rank is Second Lieutenant (5000 - 10000 Reputation Level)Arty Effem User rank is Second Lieutenant (5000 - 10000 Reputation Level)Arty Effem User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 8 h 25 m 49 sec
Reputation Power: 71
Quote:
Originally Posted by Jason Knight
I have an array of objects that I need to sort by their property xpos. I then need to set the zindex property of the object in order of xpos from lowest to highest.
Assuming xpos is an integer:
Code:
myArray.sort( function(a, b){return a.xpos - b.xpos} );

for(var i=0; i<myArray.length; i++)
 myArray[i].zIndex=i;
__________________


No it's not 'awesome' - it's just code.

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > Sorting object array by property

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap