Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

158
Views
Generating a random array of objects (randomic profile persons)

Generate an array with 10 objects of this type: { name: "Person X", (where instead of X you will put a progressive number) sex: < "M" or "F" > , (should be random) age: < number between 18 and 100) }

The result should be something like this:

[{
        "Name": "Person 1",
        "sex": "F",
        "eta": 22
    },
    {
        "Name": "Person 2",
        "sex": "F",
        "eta": 56
    },
    {
        "Name": "Person 3",
        "sex": "M",
        "eta": 33
    },
    ...
]

need to use "for"loop and Math.random to generate randomers

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Here's your solution. The following code generates 10 people with a name, sex, and eta and appends it to the people array using a for loop and Math.random.

let people = [];
for (var i = 0; i < 10; i++) {
    people.push(person = {
        Name: "Person " + (i+1),
        sex: Math.round(Math.random()) ? "M" : "F",
        eta: Math.floor((Math.random() * (100 - 18) + 18))
    });
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!