Iterating through a an array executing a switch statement returns TypeError: Cannot assign to read only property 'location' of object '#<Object>'

I have a read only array that i copied to become a mutable array let mutableForecast = [...forecast] I am taking that new array and iterating through it with forEach so i can mutate the array. im trying to use some flow control with a switch statement, but I am getting TypeError: Cannot assign to read only property 'location' of object '#<Object>'

let mutableForecast = [...forecast]
mutableForecast.forEach((obj, i) => {
    switch (obj.location) {
        case obj.location === "BRITISH_COLUMBIA":
            obj.location = "BC"
            break;
        default:
            obj.location = "oother"
    }

})

Whats the issue here? I’ve look at this, this, this and some others but cannot find an answer.

This is what the forecast array looks like before i copied it
enter image description here

174 thoughts on “Iterating through a an array executing a switch statement returns TypeError: Cannot assign to read only property 'location' of object '#<Object>'”

  1. I’m not sure where you are getting your info, but good topic.
    I needs to spend some time learning much more or understanding more.

    Thanks for magnificent information I was looking for this information for my mission.

    Reply
  2. Wow, superb blog layout! How long have you been blogging for?

    you made blogging look easy. The overall look of your website
    is great, as well as the content!

    Reply
  3. I was curious if you ever considered changing the structure of your site?
    Its very well written; I love what youve got to say. But maybe you could a
    little more in the way of content so people could connect
    with it better. Youve got an awful lot of text for only having 1 or 2 pictures.
    Maybe you could space it out better?

    Reply
  4. Thank you for another magnificent post. Where else could anybody get that kind of information in such an ideal method of writing?
    I have a presentation subsequent week, and I’m at the look for such info.

    Reply

Leave a Comment