0

I have an array as follows:

array = [{data:[{field1: blah, field2: blah, field3: blah}]},{data:[{field1: blah, field2: blah, field3: blah}]}]

I want to remove data such that my array of objects has to tag such as follows:

array = [{field1: blah, field2: blah, field3: blah},{field1: blah, field2: blah, field3: blah}]

I know I can loop through but is there a way to use array.map or some shortcut?

1
  • array = array.map(({ data }) => data); Commented Aug 31, 2021 at 0:03

1 Answer 1

1

Yeah array.map() should do the trick:

const originalArray = [{
  data: [{
    field1: "blah",
    field2: "blah",
    field3: "blah",
  }]
}, {
  data: [{
    field1: "blah",
    field2: "blah",
    field3: "blah",
  }]
}];

const mapFunction = ({ data: [obj] }) => obj;

const newArray = originalArray.map(mapFunction);

console.log(newArray);

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.