0

Creating an object with two properties address and distance. Pushing this object into darr array.

Code:

var object=new Object();
object.address=add;
object.distance=distance;
darr.push(object);

All good till now. Now I want to sort darr by each object's distance. I have tried sortOn but it gives out no results at all. Any idea how to do this?

And just to make my mind clear. Is this some kind of associative array?

2

1 Answer 1

1

In order to do that, we can just use Array.prototype.sort in a way like

dart.sort(function( a, b ) {
    return a.distance - b.distance;
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.