get Array-Object-String thing from the given Object

后端 未结 4 1653
清歌不尽
清歌不尽 2021-01-27 03:04

I have such an Object
freq = { a: 50, r: 25, m: 25 }

I want to convert it to this Array-Object like thing

         


        
4条回答
  •  北荒
    北荒 (楼主)
    2021-01-27 04:00

    You could take the entries of the object and take a destructuring assignment for the key/value pairs and map new objects with short hand properties.

    var freq = { a: 50, r: 25, m: 25 },
        dps = Object.entries(freq).map(([label, y]) => ({ label, y }));
        
    console.log(dps);

提交回复
热议问题