I have an array like the example logicData below.
I want to pass this array to a function that returns an object like the returnObject below.
In addition, using the returned object, I need to re-create the original logicData array.
Please anyone help me out. Thanks in Advance.
// array
var logicData = [
{
details: {
name: "User-1",
id: 1,
age: "38",
},
company: "XYX",
position: "Accountant",
},
{
details: {
name: "User-2",
id: 2,
age: "55",
},
company: "XYX",
position: "Sales executive",
},
{
details: {
name: "User-3",
id: 3,
age: "25",
},
company: "XYX",
position: "Engineer",
},
{
details: {
name: "User-4",
id: 4,
age: "29",
},
company: "XYX",
position: "Engineer",
},
{
details: {
name: "User-5",
id: 5,
age: "32",
},
company: "XYX",
position: "Sales executive",
}
]
How to convert the array to below format
// require object formate
const returnObject = {
first: {
details: {
name: "User-1",
id: "1",
age: "38",
},
company: "XYX",
position: "Accountant",
},
second: {
first: {
details: {
name: "User-2",
id: 2,
age: "55",
},
company: "XYX",
position: "Sales executive",
},
second: {
first: {
details: {
name: "User-3",
id: 3,
age: "25",
},
company: "XYX",
position: "Engineer",
},
second: {
first: {
details: {
name: "User-4",
id: 4,
age: "29",
},
company: "XYX",
position: "Engineer",
},
second: {
details: {
name: "User-5",
id: 5,
age: "32",
},
company: "XYX",
position: "Sales executive",
}
}
}
}
}
ANDandORof action key ?