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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:10:01+00:00 2026-06-07T00:10:01+00:00

I was surprised, if I noticed it right, that $this->Js->object() autosorts the array i

  • 0

I was surprised, if I noticed it right, that $this->Js->object() autosorts the array i have given into it. Im coding using CakePHP 2.0 Here’s what i got:

In my controller:

$arrayOfPlotPoints = array();
//....
    foreach($allFilenames as $key => $value){
        $arrayOfPlotPoints[$key]['latitude'] = $value['TransactionDetail']['latitude'];
        $arrayOfPlotPoints[$key]['longitude'] = $value['TransactionDetail']['longtitude'];
        $arrayOfPlotPoints[$key]['signal_level'] = $value['TransactionDetail']['signal_level'];
        $arrayOfPlotPoints[$key]['snr_level'] = $value['TransactionDetail']['snr_level'];
        $color = $this->ColorSchema->find('first',array('fields'=>array('ColorSchema.color'),'conditions' =>array('category' => $category, 'upper_bound >=' => $value['TransactionDetail']['snr_level'], 'lower_bound <='=> $value['TransactionDetail']['snr_level'])));
        $arrayOfPlotPoints[$key]['color'] = $color['ColorSchema']['color'];
        }

//..

In my View file:

    var test = <?php echo $this->Js->object($arrayOfPlotPoints); ?>;


    for (var key in test) {
           var obj = test[key];
           for (var prop in obj) {
                color.push(obj['color']);
                latitude.push(obj['latitude']);
                longitude.push(obj['longitude']);
               }

    }

I debugged first the value of $arrayOfPlotPoints and copied the values as it is. And I tried alerting the values that are being fetched in the for loop of my javascript. Their occurence are not alike with what i have debugged previously in my controller. It is as if it has been sorted according to value. Does this mean that JS helper autosorts its content? If that is the case, can I disable the autosort?

  • 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-07T00:10:01+00:00Added an answer on June 7, 2026 at 12:10 am

    Sorry my mistake. Thanks to the very keen eyes of this friend of mine, he found my problem.

    My array looks something like this:

    Array
    (
        [0] => Array
            (
                [latitude] => 14.62163
                [longitude] => 121.05123
                [signal_level] => -75
                [snr_level] => -5
                [key] => 0
                [color] => #000000
            )
    
        [1] => Array
            (
                [latitude] => 14.6216233333333
                [longitude] => 121.051183333333
                [signal_level] => -73
                [snr_level] => -5
                [key] => 1
                [color] => #000000
            )
    
        [2] => Array
            (
                [latitude] => 14.6216266666667
                [longitude] => 121.051146666667
                [signal_level] => -73
                [snr_level] => -5
                [key] => 2
                [color] => #000000
            )
    
        [3] => Array
            (
                [latitude] => 14.62162
                [longitude] => 121.051088333333
                [signal_level] => -75
                [snr_level] => -5
                [key] => 3
                [color] => #000000
            )
    
        [4] => Array
            (
                [latitude] => 14.6216383333333
                [longitude] => 121.051103333333
                [signal_level] => -75
                [snr_level] => -5
                [key] => 4
                [color] => #000000
            )
    
    ..........
    

    and so on.. what my code above was it iterates thru each key in my inner array thus duplicating the values i push in my javascript array depending on how many elements i fetched per loop. I hope i made myself clear there 🙂 … Anyway, here’s what I got now..

    for (var key in test) {
       var obj = test[key];
    // alert(test[key]['latitude']);
       latitude.push(test[key]['latitude']);
       longitude.push(test[key]['longitude']);
       color.push(test[key]['color']);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Somehow I never noticed until today that C++ supports nested classes. This surprised me
Surprised that i havent been able to find this myself, but anyway. Let's say
I'm surprised that MS has implemented a new feature: Validation with INotifyDataErrorInfo I have
Folks I am surprised to see my code working, that I dont have any
I have started initially with VC++ 2008 Express. I've noticed that GCC becomes kind
I'm surprised to notice that my right click code no longer works in-browser for
I have been doing some mobile web app testing and have noticed that the
I've never noticed this behavior before, but I'm surprised at the output naming conventions
I was surprised to find that Go has a 'goto' statement. I've always been
I was somewhat surprised when I realised that F#'s map implements both IDictionary<'Key, 'Value>

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.