简体   繁体   中英

How to push an array into array

data = [];
data.push({arrayName:x,secondArray: {name:x, value:y}});

Now how can you push an item into secondArray ? have tried with

data[0].secondArray.push({name:x, value:y});

But getting error like data[0].secondArray.push() is not a function.

This is because secondArray is not a array but an object .

To add properties in an object you can use

secondArray.propertyName = Value;//not to use this syntax if 'propertyName' if not a valid string.

secondArray[propertyName] = Value;

For eg use : data[0].secondArray.name = 'x';

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