-1

I am using papa parse to get fields from a google csv sheet and parses that information into JSON array. Here is an image of what my code currently returns: https://i.stack.imgur.com/toHlJ.jpg

Here's the code:

parseSites = () => {
  var url = "https://docs.google.com/spreadsheets/fakelinklol";
  var ForumCSVResults = Papa.parse(url, {
    download: true,
    header: true,
    complete: results => {
      results.data.forEach(result => {
        ForumData.push(result);
      })
    }
  })

}
console.log('Data without JSON.stringify()')
console.log(ForumData);
console.log('Data with JSON.stringify()')
console.log(JSON.stringify(ForumData))

function validate() {
  var newArr = [];
  var email = document.getElementById('email').value;
  var password = document.getElementById('password').value;
  var creds = [email, password];
  console.log(creds);
  ForumData.forEach(function(element) {
    console.log(JSON.stringify(element.email))
  })
}

ForumData.forEach doesn't even execute because apparently it is empty? I want to be able too iterate over each JSON object and compare email and password to creds. Appreciate any insight.

Barmar
  • 741,623
  • 53
  • 500
  • 612
Omi in a hellcat
  • 558
  • 1
  • 8
  • 29
  • 1
    `Papa.parse()` is asynchronous. Put everything that uses `ForumData` inside the `complete:` function. – Barmar Nov 07 '19 at 02:20

1 Answers1

0

Within complete write the following code:

console.log(JSON.parse(results))
oreopot
  • 3,392
  • 2
  • 19
  • 28