const faker = require('faker'); const colors = ['red', 'blue', 'green', 'yellow', 'orange']; const randomNumber = faker.random.arrayElement(colors); console.log(randomNumber); // Output: 'yellow'
const faker = require('faker'); const fruits = ['apple', 'banana', 'orange', 'pear', 'grape']; const randomFruit = faker.random.arrayElement(fruits); console.log(randomFruit); // Output: 'grape'In this example, we create an array of fruits and use the random arrayElement method to select a random fruit from the array and log it to the console. Overall, the random arrayElement method is useful for generating random data from arrays. It is part of the JavaScript Faker package library.