-4

Need to convert array objects given below

[{ key:"url", value:"new" },{ key:"page", value:1 }]  // after (need to convert like this)
{ url:"new", page:1 }  // before
3
  • Please, do some research before asking. Commented Feb 8, 2021 at 14:31
  • Are all "before" objects structured as shown? Likewise with the "after" objects? BTW, this is not really an angular question. Commented Feb 8, 2021 at 14:31
  • I want conversion vice versa Commented Feb 8, 2021 at 14:33

1 Answer 1

2

You can use Object.entries() :

const array = [];

Object.entries({ url: "new", page: 1 }).forEach(([key, value]) => {
  array.push({ key, value })
})

console.log(array)

Sign up to request clarification or add additional context in comments.

2 Comments

{ url:"new", page:1 } Need to convert like below [{ key:"url", value:"new" },{ key:"page", value:1 }]
it's the purpose of the code sample. see it in action here : stackblitz.com/edit/rxjs-gasfg5?devtoolsheight=60

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.