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

  • Home
  • SEARCH
  • 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 7636511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:42:01+00:00 2026-05-31T07:42:01+00:00

I have a created 4 dimensional array in JavaScript. One column contains String values

  • 0

I have a created 4 dimensional array in JavaScript. One column contains String values and the other three columns contain float values. I filled the first 3 columns from a JSON response and the fourth column contains the magnitude of the values col2 and col3. I need to sort the entire array based on the values in col4. Following code shows how I created the array. Can someone please tell me how to sort this array based on col4?

     var labels = responseJSON.labels;
     var knowledge = responseJSON.knowledge;
     var interest = responseJSON.interest;

     var label_know_int_array = new Array(3);
     //array item 0 contains all the labels
     label_know_int_array[0] = new Array(200);
     //array item 1 contains knowledge values
     label_know_int_array[1] = new Array(200);
     //array item 2 contains all the interest values
     label_know_int_array[2] = new Array(200);
    //array item 3 contains the magnitude of knowledge and interest
     label_know_int_array[3] = new Array(200);

     for(var i=0;i<labels.length;i++)
         {
                label_know_int_array[0][i] = labels[i];
                var knowVal = knowledge[i];
                var intVal = interest[i];
                label_know_int_array[1][i] = knowVal;
                label_know_int_array[2][i] = intVal ;

                var squareSum = (knowVal*knowVal) + (intVal*intVal);
                var distance = Math.sqrt(squareSum);
                label_know_int_array[3][i] = distance ;


         }
  • 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-05-31T07:42:03+00:00Added an answer on May 31, 2026 at 7:42 am

    You can use native Array.sort() method

    Array.sort method accepts a callback for custom sorting

    here is a sample code

    var arr = [
      {
        id : 5,
        name : "john"
      },
      {
        id : 2,
        name : "Sam"
      },
      {
        id : 6,
        name : "adams"
      }
    ];
    
    // custom sort
     arr.sort(function (a, b) {
        if (a.id > b.id) {
           return 1;   //return any +ve values
        } else if (a.id < b.id) {
           return -1;  // return any -ve values
        } else {
           return 0;  // return zero for equal values
        }
     });
    

    Using this callback you can implement your custom sorting functionality

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

Sidebar

Related Questions

I have a multi dimensional array, like this: array('name' => array('title'=>'Title','date'=>'Created')) I store it
I have the following three arrays and need to create a new two-dimensional array
I have to send a two-dimensional JavaScript Array to a PHP page. Indeed, I'm
Supposing I have a 2 dimensional array which was created with something like this,
I have an array of documents, where each document have another simple one-dimensional array
In C#, i have created ArrayList using structures. so it creates multi dimensional array
I have created one table using the below command: create table Table1( Id int
I have a JSON file that I would like to create an multi-dimensional array
I have a two dimensional array with coordinates and i want to make the
I have a two dimensional array of points, which constitute a map. The black

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.