Created
December 3, 2023 08:54
-
-
Save stephengade/e1469881df7ba3fa61c2fe0c0633854b to your computer and use it in GitHub Desktop.
Generate Random User Data with For Loop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export interface iProfile { | |
name: string; | |
email: string; | |
photo: string; | |
username: string; | |
role: "Frontend Developer" | "Backend Developer" | "Fullstack Developer"; | |
} | |
export const data: iProfile[] = []; | |
// generate random names | |
const RandomNames = [ | |
"Alice", | |
"Bob", | |
"Charlie", | |
"David", | |
"Eve", | |
"Frank", | |
"Grace", | |
"Henry", | |
"Ivy", | |
"Jack", | |
"Kate", | |
"Liam", | |
"Mia", | |
"Noah", | |
"Olivia", | |
"Peter", | |
"Quinn", | |
"Rose", | |
"Sam", | |
"Tina", | |
"Uma", | |
"Victor", | |
"Wendy", | |
"Xander", | |
"Yara", | |
"Zane", | |
"Abigail", | |
"Benjamin", | |
"Chloe", | |
"Daniel", | |
"Emily", | |
"Fiona", | |
"George", | |
"Hannah", | |
"Isaac", | |
"Julia", | |
"Kevin", | |
"Lily", | |
"Mason", | |
"Nora", | |
"Oscar", | |
"Penelope", | |
"Quentin", | |
"Rachel", | |
"Simon", | |
"Tiffany", | |
"Ulysses", | |
"Violet", | |
"William", | |
"Xavier", | |
"Yasmine", | |
"Zoey", | |
"Stephen", | |
"Gerrard", | |
"Adewale", | |
]; | |
// Generate 50 sample profiles | |
for (let i = 1; i <= RandomNames.length; i++) { | |
if (RandomNames[i]) { | |
const profile: iProfile = { | |
name: RandomNames[i], | |
role: | |
i % 3 === 0 | |
? "Backend Developer" | |
: i % 2 === 0 | |
? "Frontend Developer" | |
: "Fullstack Developer", | |
email: `${RandomNames[i].toLowerCase()}@example.com`, | |
username: `user${RandomNames[i].toLowerCase()}_username`, | |
photo: `https://source.unsplash.com/random/200x200?sig=${i}`, | |
}; | |
data.push(profile); | |
} else { | |
console.error("Please wait..."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment