0

as title, I encounter a problem that is my json data was parsed by javascript and it seems also sorted my array data, but original data is correct.

My data is use Laravel to get data, and the data in PHP is also correct.

The original data:

"product_detail":{
    "280": {
        "condiment": {
            "17": { ... },
            "16": { ... }
        }
    }
}

but, when I console.log it, the data will be like:

"product_detail":{
    "280": {
        "condiment": {
            "16": { ... },
            "17": { ... }
        }
    }
}

I don't know is Javascript automatically sort data or not?

Can anyone help me?

ChaCha
  • 67
  • 5
  • index-like numerical keys are always enumerated first and in ascending order in a javascript object. – adiga Nov 14 '22 at 05:53
  • Nothing is automatically sorted or parsed. I think you can check the type of element at some point where you think it's changing types. Maybe just like @adiga is suggesting. this could be true in your case. – Wasif Jameel Nov 14 '22 at 05:56

0 Answers0