Issue
I have a object and I can try to convert this object in a special array,
This is the index
const index = 3
This is my object
object = { fruit: apple vegetable: carrot number: 5 color: red }
This is the array structure that I want to achieve
[ 3: { fruit: apple vegetable: carrot number: 5 color: red } ]
I´m not expert in arrays but I try this and dont´t convert in array with the special structure
this.object.entries(newObj).map(x => { return index[x] })
Please could you help me, I would really appreciate your help.
Solution
Generate a new array with required length and assign the object to required index
const index = 3
const myObject = { fruit: 'apple', vegetable: 'carrot', number: 5, color: 'red' }
const op = new Array(index + 1);
op[index] = myObject;
Answered By - Nitheesh
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.