Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to remove object key value of an object array?

I have an object array with object key value.

arr = [obj1:{name:"Jack", surname:"Peralto"}, obj2:{name:"Husnu", surname:"White"}]

I do not want to see obj1 and obj2 labels. Because of these labels I could not use a word template package.

So I want to convert it to this form.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

arr = [{name:"Jack", surname:"Peralto"}, {name:"Husnu", surname:"White"}]

.map function does not work at first array.

arr.map(o=>o)

Why I have an array like this? I should use reduce function and obj1 and obj2 labels are key value when I create object array. Now I don’t need them.

>Solution :

When you fix the syntax errors in your code ([obj1:{... is not a valid data structure) you can use Object.values to get at the nested objects.

const obj = {
  obj1: {
    name: "Jack",
    surname: "Peralto"
  },
  obj2: {
    name: "Husnu",
    surname: "White"
  }
};

console.log(Object.values(obj));
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading