-2

I am learning javascript. I have an array that looks like :

myArray = [{
      "item":{
         "fields":{
            "myfield":"Value1"
         }
      }
   },
   {
      "item":{
         "fields":{
            "myfield":"Value2"
         }
      }
   }];

I want to create a new array with ["Value1","Value2"].

How should I do that ?

Thanks a lot !

1

1 Answer 1

0

You can use the Javascript function map() for this. :

const myArray = [{
      "item":{
         "fields":{
            "myfield":"Value1"
         }
      }
   },
   {
      "item":{
         "fields":{
            "myfield":"Value2"
         }
      }
   }];

const r = myArray.map(e => e.item.fields.myfield)
console.log(r)

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.