How to traverse the key of an object sequentially

the following is the data returned by the background
clipboard.png

[
  {
    "D": 2750000.0,
    "": 2142172.1467,
    "": 1000000.0,
    "": 0.0,
    "for": 1000000.0,
    "": 9000000.0,
    "": 1500000.0,
    "W": 2000000.0,
    "D": 5100000.0
  },
  {
    "D": 2750000.0,
    "": 2142172.1467,
    "": 1000000.0,
    "": 0.0,
    "for": 1000000.0,
    "": 9000000.0,
    "": 1500000.0,
    "W": 2000000.0,
    "D": 5100000.0
  },
  {
    "D": 2750000.0,
    "": 2142172.1467,
    "": 1000000.0,
    "": 0.0,
    "for": 1000000.0,
    "": 9000000.0,
    "": 1500000.0,
    "W": 2000000.0,
    "D": 5100000.0
  },
  {
    "D": 2750000.0,
    "": 2142172.1467,
    "": 1000000.0,
    "": 0.0,
    "for": 1000000.0,
    "": 9000000.0,
    "": 1500000.0,
    "W": 2000000.0,
    "D": 5100000.0
  },
  {
    "D": 2750000.0,
    "": 2142172.1467,
    "": 1000000.0,
    "": 0.0,
    "for": 1000000.0,
    "": 9000000.0,
    "": 1500000.0,
    "W": 2000000.0,
    "D": 5100000.0
  },
  {
    "D": 2750000.0,
    "": 2142172.1467,
    "": 1000000.0,
    "": 0.0,
    "for": 1000000.0,
    "": 9000000.0,
    "": 1500000.0,
    "W": 2000000.0,
    "D": 5100000.0
  },
  {
    "D": 2750000.0,
    "": 2142172.1467,
    "": 1000000.0,
    "": 0.0,
    "for": 1000000.0,
    "": 9000000.0,
    "": 1500000.0,
    "W": 2000000.0,
    "D": 5100000.0
  },
  {
    "D": 2750000.0,
    "": 2142172.1467,
    "": 1000000.0,
    "": 0.0,
    "for": 1000000.0,
    "": 9000000.0,
    "": 1500000.0,
    "W": 2000000.0,
    "D": 5100000.0
  },
  {
    "D": 2750000.0,
    "": 2142172.1467,
    "": 1000000.0,
    "": 0.0,
    "for": 1000000.0,
    "": 9000000.0,
    "": 1500000.0,
    "W": 2000000.0,
    "D": 5100000.0
  }
]

I need to put the push of the key order in the object into an array, and the final result
["Cross Star", "leisurely Farm", "Avatar", "Seven six Project", "for".]
because the key of objects returned by for in and Object.keys () are unordered, they can"t get the correct order at all

at present, my idea is as follows: since the returned key is unordered, then simply use the array order obtained by Object.keys to reorganize the returned list
result is still not good. Please tell me what to do

.
Object.keyscolumns
let columns = [];
let once = []
   list.forEach((item, current) => {
     columns = Object.keys(item)
   })
columns obj
list.forEach(item => {
          let obj = {};
          columns.forEach(c => {
            obj[c] = item[c]
            // console.log(obj)
            // console.log(c," :",item[c])
          })
          once.push(obj)
        })
Mar.18,2022

        let obj = {
            "D": 2750000.0,
            "": 2142172.1467,
            "": 1000000.0,
            "": 0.0,
            "for": 1000000.0

        }

        function json2arr(obj) {
            let arr = JSON.stringify(obj).replace(/^{|}$/g, '').split(',')
            return arr.map((item) => {
                return item.split(":")[0]
            })
        }
        console.log(json2arr(obj))


The

object itself is unordered, and the console prints according to the rules specified by each engine, which does not represent itself.

you all since the returned key is unordered, why use the array order obtained by Object.keys and why go to to reorganize the returned list ? Isn't traversing the array directly the key value of the traversing object? This order is not right, you can also sort according to your rules, but usually write a dead array, if it is not fixed, then let the background pass it.

var arr = [...]
var keys = ['k1','k2'...]
arr.forEach(item=>{
    keys.forEach(key=>{
        console.log( item[key] )
    })
})

how does key still have Chinese? this is not in accordance with the specification. If you only want to traverse the key, in each object, you can use the for in loop


Brother, you are not right. What I know is that if the key value of the object is a number, or if it can be converted into a number with parseInt, the key value will be sorted, and there will be disorder, but there are no numbers in your case. I tried to output it in a normal order, ah, I used chrome. How do you explain this

?
Menu