0

How can i access this type of structure in java script. i want to access these emails one by one.

          var somevar[];
       console.log(somevar);
     **Below is the result**-:
      [ {email: 'xyz@gmail.com' },
      { email: 'xyz@gmail.com' },
      { email: 'xyz@gmail.com' },
      { email: 'xyz@gmail.com' }]

At last i want to send email to the above email ids.Now how to put a loop on somevar to access the list of emails

Vishu
  • 35
  • 1
  • 6
  • You may use `forEach()` or a simple for loop. – Mohammad Usman May 10 '18 at 07:36
  • https://developer.mozilla.org/en-US/docs/Learn/Getting_started_with_the_web/JavaScript_basics – Daniel Krom May 10 '18 at 07:38
  • 2
    Possible duplicate of [How to loop through an array containing objects and access their properties](https://stackoverflow.com/questions/16626735/how-to-loop-through-an-array-containing-objects-and-access-their-properties) – Mohammad Usman May 10 '18 at 07:42

1 Answers1

1

Using pure JavaScript function forEach() you can do it.

Below is working code:

let input = [{
    email: 'xyz@gmail.com'
  },
  {
    email: 'xyz@gmail.com'
  },
  {
    email: 'xyz@gmail.com'
  },
  {
    email: 'xyz@gmail.com'
  }
];

input.forEach(function(ele) {
  console.log(ele.email);
  // send email to each email ID here.
});
Vikasdeep Singh
  • 20,983
  • 15
  • 78
  • 104