0
0

More than 1 year has passed since last update.

jsでobjectのキーの順序を変更する

Posted at

{
    address:'',
    age:'',
    client_name:'',
    customer_id:'',
    first_visit_date:'',
    prefecture:'',
}

jsのobjectのキーを自分の指定した、順序に並び替える方法。

//json並び替え key_orderの順番に並び替える
 let key_order = ['address','client_name','first_visit_date','prefecture','customer_id','age']
 let hash = {}
 let items_data = key_order.map(function(x){
   return json.items[0][x]
 })

 for (let [i,j] of zip(key_order,items_data)){
   hash[i] = j
 }
 json.items[0] = hash

参考文献:
https://teratail.com/questions/106913

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0