1

I have an array of objects:

var arr = [{"name":"first", value:"170"},
{"name":"second", value:"150"},
{"name":"second", value:"250"}]

How can I sort it by value?

1 Answer 1

2

You could use Array#sort with a callback for the values.

var arr = [{ "name": "first", value: "170" }, { "name": "second", value: "150" }, { "name": "second", value: "250" }];

arr.sort(function (a, b) {
    return a.value - b.value;
});

console.log(arr);

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.