{"action":"created","issue":{"url":"https://api.github.com/repos/processing/p5.js/issues/1072","labels_url":"https://api.github.com/repos/processing/p5.js/issues/1072/labels{/name}","comments_url":"https://api.github.com/repos/processing/p5.js/issues/1072/comments","events_url":"https://api.github.com/repos/processing/p5.js/issues/1072/events","html_url":"https://github.com/processing/p5.js/issues/1072","id":114861892,"number":1072,"title":"Array / Object / Json","user":{"login":"fredericpierron","id":1943575,"avatar_url":"https://avatars.githubusercontent.com/u/1943575?v=3","gravatar_id":"","url":"https://api.github.com/users/fredericpierron","html_url":"https://github.com/fredericpierron","followers_url":"https://api.github.com/users/fredericpierron/followers","following_url":"https://api.github.com/users/fredericpierron/following{/other_user}","gists_url":"https://api.github.com/users/fredericpierron/gists{/gist_id}","starred_url":"https://api.github.com/users/fredericpierron/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fredericpierron/subscriptions","organizations_url":"https://api.github.com/users/fredericpierron/orgs","repos_url":"https://api.github.com/users/fredericpierron/repos","events_url":"https://api.github.com/users/fredericpierron/events{/privacy}","received_events_url":"https://api.github.com/users/fredericpierron/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-11-03T17:01:32Z","updated_at":"2015-11-03T17:16:56Z","closed_at":"2015-11-03T17:04:57Z","body":"Object in array can not be accessed.\r\n\r\n```Javascript\r\nvar reserve;\r\n\r\nfunction preload() {\r\n  var fichier = '2014_reserve.json';\r\n  reserve = loadJSON(fichier, fichierOK);\r\n}\r\n\r\nfunction setup() {\r\n  createCanvas(500, 500);\r\n  var test = reserve.length;\r\n}\r\n\r\nfunction draw() {\r\n  background(200);\r\n  \r\n\r\n}\r\n\r\nfunction fichierOK() {\r\n  println(\"Le fichier est chargé\");\r\n  background(255);\r\n  \r\n  var depenseTotale = 0;\r\n  \r\n  for (i=0; i<=reserve.length; i++){\r\n    depense = reserve[i][\"Montant\"];\r\n    depenseTotale += depense;\r\n  }\r\n\r\n}\r\n````\r\nHere's the Json\r\n\r\n```json\r\n[\r\n  {\r\n    \"Bénéficiaire\":\"Télé Bocal\",\r\n    \"Adresse\":\"Maison des associations\\n1/3 rue Frédérique Lemaître\\n75020 Paris\",\r\n    \"Descriptif\":\"Mise en œuvre d'ateliers de production locale proposant d’utiliser l'image comme une valorisation du travail des artistes\",\r\n    \"Montant\":5000,\r\n    \"Nom\":\"BAUPIN\",\r\n    \"Prénom\":\"Denis\",\r\n    \"Département\":\"Paris\",\r\n    \"Groupe\":\"Ecolo\",\r\n    \"Programme budgétaire\":\"313-03\",\r\n    \"ID_Acteur\":\"PO609016\"\r\n  },\r\n  {\r\n    \"Bénéficiaire\":\"Mieux se déplacer à Bicyclette\",\r\n    \"Adresse\":\"MDB –\\n37 boulevard Bourdon\\n75004 Paris\",\r\n    \"Descriptif\":\"Réalisation des supports de communication pour faire connaître ses nouvelles dispositions sur l'usage de la bicyclette et diffusion\",\r\n    \"Montant\":4000,\r\n    \"Nom\":\"BAUPIN\",\r\n    \"Prénom\":\"Denis\",\r\n    \"Département\":\"Paris\",\r\n    \"Groupe\":\"Ecolo\",\r\n    \"Programme budgétaire\":\"203-15\",\r\n    \"ID_Acteur\":\"PO609016\"\r\n  }\r\n]\r\n```\r\n\r\nThe problem is here:\r\n```Javascript\r\n  for (i=0; i<=reserve.length; i++){\r\n    depense = reserve[i][\"Montant\"];\r\n    depenseTotale += depense;\r\n  }\r\n````\r\nIt should be possible to access to any value of the object by using:\r\n```Javascript\r\ndepense = reserve[i][\"Montant\"];\r\n```\r\nor \r\n```Javascript\r\ndepense=reserve[i].Montant;\r\n````\r\nIn both cases, I get an error \r\n```\r\nUncaught TypeError: Cannot read property 'Montant' of undefined\r\n```"},"comment":{"url":"https://api.github.com/repos/processing/p5.js/issues/comments/153422534","html_url":"https://github.com/processing/p5.js/issues/1072#issuecomment-153422534","issue_url":"https://api.github.com/repos/processing/p5.js/issues/1072","id":153422534,"user":{"login":"lmccart","id":191056,"avatar_url":"https://avatars.githubusercontent.com/u/191056?v=3","gravatar_id":"","url":"https://api.github.com/users/lmccart","html_url":"https://github.com/lmccart","followers_url":"https://api.github.com/users/lmccart/followers","following_url":"https://api.github.com/users/lmccart/following{/other_user}","gists_url":"https://api.github.com/users/lmccart/gists{/gist_id}","starred_url":"https://api.github.com/users/lmccart/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lmccart/subscriptions","organizations_url":"https://api.github.com/users/lmccart/orgs","repos_url":"https://api.github.com/users/lmccart/repos","events_url":"https://api.github.com/users/lmccart/events{/privacy}","received_events_url":"https://api.github.com/users/lmccart/received_events","type":"User","site_admin":false},"created_at":"2015-11-03T17:16:56Z","updated_at":"2015-11-03T17:16:56Z","body":"also, this tutorial might be helpful for more general strategies for debugging:\r\np5js.org/tutorials/debugging/"}}