Array of Objects/Arrays

Hello,

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:
aimobjekte

Greetings
Chorum

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"
    arr.push(obj)
}
//node.warn(arr)
msg.payload = arr
return msg;
2 Likes

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!

Chorum

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