Skip to content Skip to sidebar Skip to footer

How Do I Add Each Item From My For Loop Onto My Array Reactjs

I'm trying to allow users to select mp3 tracks from a directory and have it display in a playlist on the screen. So far I'm using a for loop to grab each of the files but I'm not s

Solution 1:

try this instead:

const fileList = [];

for(var x = 0, xlen = this.files.length; x < xlen; x++) {
  file = this.files[x];
  name = file.name;
  console.log(name);
  fileList.push({name:name});
  //append {name: 'file.name'} x amount of times to files: [] //
}

 self.setState({ files: fileList });

Post a Comment for "How Do I Add Each Item From My For Loop Onto My Array Reactjs"