简体   繁体   中英

Multidataset, multidimensional array of objects in JS and in Node

I am stuck with the problem. Is there a difference between arrays in examples below:

This one in React:

const multiDataSet = [
    {
        columns: [
            {title: "Last name", width: {wpx: 150}}
        ],
        data: []
    }
];

Same time in NodeJS server side:

const tmp = [
                    {
                        user:[]
                    }
            ];

I am trying to do in a cycle on NodeJs server side:

tmp.[i].user.push(somevar);

It's saying that [ is unexpected. But same time in React I can do the below and it's working:

multiDataSet.[0].data.push(somevar);

What can be wrong here?

There should not be a . before accessing array item using index in any of the following cases.

Change

tmp.[i].user.push(somevar);

to

tmp[i].user.push(somevar);

and Change

multiDataSet.[0].data.push(somevar);

to

multiDataSet[0].data.push(somevar);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM