Search code examples
javascriptarraysreactjsjavascript-objects

Concat results of single function in JavaScript


const example = e => {
        console.log(e);
    };

Each time an API call is made, example() or rather e gives back different strings, such as:

string one string two string three

Is there a way to concat all these strings into one array?


Solution

  • let arr = [];
    const example = e => {
      arr.push(e);
      console.log(e);
    };