Array of Objects/Arrays


i would like to use an array of objects but i can only create that array manually. I dont know how to create a bigger one :frowning:

My Code:

var test

let arrayOfObjects = [{},{}]

arrayOfObjects[1]['d'] = 777;

test = arrayOfObjects[1]['d'];

msg.logs = test

So i created an Array with 2 Objects. How do i create an Array with 100 Objects ? I could manually set 100 {}, but there must be a better way :slight_smile:

I would like to go with an loop through that array.

The Payload what i want to get into that array looks that way:


If you do search 'create array of objects javascript' world wide, there is too many examples that nobody can't even count ...

let arr = []
let obj
for(let i=0;i<100;i++){
    obj = {}
    obj.someProperty = Math.random()
    obj.someOtherProperty = "Something"
msg.payload = arr
return msg;

I didnt understand the examples i found, so i tried to build it up myself.

It tooked until now for me to make that code functional for me :slight_smile:

Thank you for your help!


This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.