I am getting Json in this format from server
Details:{1:"John",2:"Josh"}
I want to convert it into this FormArray format
Details:[{"Number": 1, "Name": John},{"Number": 2, "Name": Josh}]
How can I achieve it? I am using Angular 8.
try this
const input = { 1: "John", 2: "Josh" };
let Details = [];
for (let key of Object.keys(input)) {
let detail = { "Number": key, "Name": input[key] };
Details.push(detail);
}
I suggest if you have access to the server code you should modify it to return the data in the format you want, as this will slow down your application (frontend) when the server returns an object containing say 1000+ items.