Can’t get object property in lightning component controller

I am trying to access JS object properties in the client controller. I get undefined if I try access it by name. But I see the properties if I log the whole object. Something I am missing?

  var uploadedFiles = event.getParam("files");
    //var objectParsed = JSON.parse(uploadedFiles);
    var docId = uploadedFiles["name"];
    for (var key in uploadedFiles) {
          if (uploadedFiles.hasOwnProperty(key)) {

Console output

enter image description here


Your JSON [{"name":"xxx","documentId":"xxx"}] looks like an array, not an object.

Change the way you get the docId to

var docId = uploadedFiles[0]["name"]; or var docId = uploadedFiles[0].name;

and the loop to

for (var key in uploadedFiles[0]) {

Source : Link , Question Author : Allen Mann , Answer Author : Sebastian Kessel

Leave a Comment