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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.