-2

I have an Object which is empty at the beginning,

var theList = {}

I need to populate it with random key value pairs and the final structure of the object should be like this:

theList{
  id1{
    fname: "some Name"
    lname: "some Last Name"
  }
  id2{
    fname: "some OTHER Name"
    lname: "some OTHER Last Name"
   }
   ...
   ...
   ...
}

**NOTE: ** the number "1" and "2" of id1 and id2 must be generated dynamically

str
  • 42,689
  • 17
  • 109
  • 127
Buddika
  • 13
  • 3
  • 1
    This is a question and answer site, not a code writing service. „I need“ is not a question, so this post is off topic. – Patrick Hund Feb 24 '18 at 07:42
  • If you have tried something that isn't working, please include that here. Otherwise this is nothing more than homework we're doing for you. – Deryck Feb 24 '18 at 07:43

2 Answers2

0

In these cases I usually use this nom package: https://github.com/marak/Faker.js/

ema
  • 5,668
  • 1
  • 25
  • 31
0

Loop over a set of number and create the object key by appending id with the number

let theList = {};

for (let i = 0; i < 10; i++) {
  theList['id' + i] = {
    fname: "some Name",
    lname: "some Last Name"
  }


}

console.log(theList)
brk
  • 48,835
  • 10
  • 56
  • 78