js - How to change one key's value based on another key's value in array of objects

后端 未结 4 1052
眼角桃花
眼角桃花 2021-01-29 05:01

I have an array of objects like this:

var chartData = [{count: 0, idTag: \"24\"}
                 {count: 0, idTag: \"25\"}
                 {count: 0, idTag: \"         


        
4条回答
  •  Happy的楠姐
    2021-01-29 05:39

    If you're free to change the structure of chartData, why not just make it a hash instead of an array?

    var chartData = {24: 0,
                     25: 0,
                     26: 0};
    

    And then the loop becomes

    for (i=0; i

提交回复
热议问题