get Array-Object-String thing from the given Object

后端 未结 4 1654
清歌不尽
清歌不尽 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 03:37

    Try this, I think it is the most performant way to do it, because .map() is slower than simple for loop:

    let freq = { a: 50, r: 25, m: 25 } ;
    let dps = [];
    
    for (let prop in freq) {
        dps.push({
            label: prop,
            y: freq[prop]
        });
    }
    
    console.log(dps);

提交回复
热议问题