Sometimes during testing a front-end feature, we might need some dummy data. This data might be in the form of numbers, list of words or list of objects. Let’s have a look at how we can define a list of words with length N.
Initially, we could define a few words, and then we could pick them up randomly to generate a long list of words.
In the code above, we’re filling an array by passing an index to the createWord method. This method picks up a random name from the list of six names. We then append the index i to the name to make it unique.
Of course, we can modify the code further to have it return a list of objects instead:
In the code above, we’re creating an object using the createObject method. It simply takes in an index number and uses it as an id for the object. Along with the number appended to the randomly picked name for title.