Is there a more elegant way to iterate over json array in js?

I am trying to iterate over a json array and calculate number of hours from every object. The code works but it just feels like there could be a more efficient way to write the code, but whatever I try the code just breaks.

My json array:

{
    "timesheetItems":[
        {
        "id":"1",
        "title":"Ticket system integration",
        "hours":2
        },
        {
        "id":"2",
        "title":"Integration with Google Maps API",
        "hours":3
        },
        {
        "id":"3",
        "title":"Prepare test cases",
        "hours":4
        }
    ]
}

Iteration:

let numberOfSheets = 0;
const lam = this.state.sheets.forEach( item => numberOfSheets += item.hours)

88 thoughts on “Is there a more elegant way to iterate over json array in js?”

  1. i need a private loan lender, i need a loan now with no job. i need a loan have no credit need loan now i need a loan today i need an emergency loan now, cash advance loans new york state, cash advance online, cash advance loans, cash advance loans with a prepaid debit card. Economics study of those business, terms of credit.

    Reply

Leave a Comment