Just starting out with Java Script and I have an array of objects like this:
[{
firstName: "John",
lastName: "Doe",
age: 46
},
{
firstName: "Mike",
lastName: "Jeffrey",
age: 56
}]
I want to transform this array of objects into a multi-dimensional array like this:
[
[{
firstName: "John",
lastName: "Doe",
age: 46
}],
[{
firstName: "Mike",
lastName: "Jeffrey",
age: 56
}]
]
This is the code I am using to achieve this transformation:
var actualResult = [];
var arrayLength = inputObj.length;
for (var i = 0; i < arrayLength; i++) {
var tempResult = [];
tempResult.push(inputObj[i]);
actualResult.push(tempResult);
}
The variable `inputObj` represents my initial input data. Is this approach correct for what I'm trying to do?