close

[Solved] Object is not extensible error when creating new attribute for array of objects

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Object is not extensible error when creating new attribute for array of objects in javascript. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Object is not extensible error when creating new attribute for array of objects Error Occurs?

Today I get the following error Object is not extensible error when creating new attribute for array of objects in javascript.

How To Solve Object is not extensible error when creating new attribute for array of objects Error ?

  1. How To Solve Object is not extensible error when creating new attribute for array of objects Error

    To Solve Object is not extensible error when creating new attribute for array of objects Error data = JSON.parse(JSON.stringify(data)));

  2. Object is not extensible error when creating new attribute for array of objects

    To Solve Object is not extensible error when creating new attribute for array of objects Error data = JSON.parse(JSON.stringify(data)));

Solution 1

You probably need to copy the objects:

export const initSelect = (data) => {
 return data.map((item) => ({
     ...item,
     selected: false       
 }));
}

Solution 2

data = JSON.parse(JSON.stringify(data)));

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also Read

Leave a Comment