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 9222455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:50:19+00:00 2026-06-18T03:50:19+00:00

Trying to arrange an array based on the order of another array function Sort(old,

  • 0

Trying to arrange an array based on the order of another array

function Sort(old, new){
  var temp = [];
   for(var i=0; i<old.length; i++){
        temp[i] = old[new[i]];
   }
  return temp;
}

Is it possible to achieve the same without the use of a temp[] additional array?

  • 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-18T03:50:20+00:00Added an answer on June 18, 2026 at 3:50 am

    First of all I’d like to note that new is a keyword that should probably be avoided as a variable name.

    jQuery’s map will let you do that, although it’s quite possible a temp variable is used internally. The nice thing about that project is that it will continue to improve and even if that function is currently inefficient it might be more efficient later without having to call it a different way.

    Here’s a one-liner if you’re not opposed to using jQuery:

    var oldArray = ['a', 'b', 'c', 'd'],
        newOrder = [1, 3, 0, 2];
    
    oldArray = jQuery.map(newOrder, function(val) { return oldArray[val]; });
    

    That should reorder oldArray to ['b', 'd', 'a', 'c']. However, you’re still replacing oldArray with a new array object. It really depends on what you’re trying to accomplish. I don’t think you’ll be able to fully avoid temporary variables, but there are different solutions depending on whether you’re going for simplicity, speed efficiency, memory efficiency, or something else.

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

Sidebar

Related Questions

I'm trying to arrange an array of movies in alphabetical order, ignoring case. My
I am trying to arrange this multidimensional array to ascending or descending. However, I
I'm trying to figure out how to sort a 2d array into a 3d
I'm trying to re-arrange words into alphabetical order. For example, tomato would become amoott,
I'm trying to return a (square) section from an array, where the indices wrap
I'm trying to arrange a group of pages in to an array and place
I am trying to use a wxSizer to arrange widgets inside a panel. I
Im trying to create an array of object from ul li tags using jQuery
I am trying to bind a 2D array of buttons arranged in stackpanels to
I'm trying to limit the number of objects in an array controller, but 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.