Is there a built-in lodash function to take this:
let params = ['foo', 'bar', 'baz', 'zle'];
let newArray = [];
params.forEach((element, index) => {
let key = "name" + index;
newArray.push({ key: element })
});
console.log(newArray);
And expected output should be like this:
var object = {
a: {
name1: "foo",
name2: "bar",
},
b: {
name1: "baz",
name2: "zle",
}
}
aandbin output. i.e what is the deciding on where to break the array params. You can simply useObject.assign()to convert Array to object, But output onparamswill be single dimension object. Refer this stackoverflow.com/questions/4215737/convert-array-to-objectaandbdummy keys?