Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8276951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:32:30+00:00 2026-06-08T08:32:30+00:00

I have the following JavaScript array, var myArr= [{ key : Consumer Discretionary, values

  • 0

I have the following JavaScript array,

var myArr= [{
    "key" : "Consumer Discretionary",
    "values" :[ 
               [1146369600000, 26.425199957521],
               [1138683600000, 27.38478809681],
               [1141102800000, 27.371377218208], 
               [1143781200000, 26.309915460827] 
              ]}, 
    {
     "key" : "Consumer Staples",
     "values" :[
                [1159588800000, 7.2800122043237], 
                [1141102800000, 7.1187787503354], 
                [1167541200000, 8.351887016482], 
                [1146369600000, 8.4156698763993]
              ]}
     ];

How can I sort the “values” of “key” Consumer Discretionary and then Consumer Staples in ascending order so it will look like

Consumer Discretionary :-

[1138683600000, 27.38478809681] 
[1141102800000, 27.371377218208] 
[1143781200000, 26.309915460827]
[1146369600000, 26.425199957521]

Any help on this ?
Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T08:32:32+00:00Added an answer on June 8, 2026 at 8:32 am

    Try the following:

    function valuePredicate(a,b){
        return a[0]!==b[0] ? a[0]-b[0] : a[1]-b[1];
    }
    
    for(var i=0; i < myArr.length;++i){
        myArr[i].values.sort(valuePredicate);
    }
    

    Live demo

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say I have the following array in JavaScript: var skins = new Array('Light',
I currently have the following javascript array: var stuffs = ['a', 'b']; I pass
I have the following JavaScript array of real estate home objects: var json =
I have the following array defined in JavaScript, var myPriceList = [0, 0, 0,
I have the following code: <script type=text/javascript> var checksSinceLastPostBack = new Array(); function clientSelectedIndexChanged(sender,
I have the following JavaScript array: var President = new Array(); President[0]=Thomas Jefferson; President[1]=Thomas
I have the following JavaScript data structure. a[] is an array with text strings
I have the following JavaScript code: var x = ['CFMG','JMFMG','CPMAF']; var y = $.param({'test':x});
I have the following JavaScript code: oCoord = {x: null, y: null}; var aStack
I have the following in javascript: var entriesString = ''; $$('select[id=shopId]').each(function(elem, i){ shops[i] =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.