Home > front end >  Could you tell me how to array to object the react
Could you tell me how to array to object the react

Time:09-16

The react array const arr1=[
{" id ":" 1 ", "key_name" : "a", "key_value" : "aaa"},
{" id ":" 2 ", "key_name" : "b", "key_value" : "BBB"},
{" id ", "3", "key_name" : "c", "key_value" : "CCC"},
{" id ", "3", "key_name" : "d", "key_value" : "DDD"},

];
To turn to the object obj={" a ":" aaa ",
"B", "BBB",
"C", "CCC",
"D" : "DDD"}

Which master know how to convert, please?

CodePudding user response:

Var obj={}
for(var i=0; iObj [arr1 [I] key_name]=arr1 [I] key_value
}
The console. The log (obj)

CodePudding user response:

Let arr=arr1. The map (item=& gt; {
Let obj={};
Obj [item key_name]=item. Key_value;
Return obj.
})
  • Related