structobject._childElements.push(element);

You're trying to modify the (non-existent) _childElements property of the Constructor function instead of the instance you created with new structobject.

Use this instead of structobject on that line.


It is conventional, in JavaScript, to use variables starting with capital letters for constructor functions.

var structobject = function(...) {

would be better written as:

var Structobject = function(...) {

or (since it is a constructor that makes objects):

var Struct = function(...) {

or (because named functions are easier to deal with in debuggers):

function Struct (...) {
Answer from Quentin on Stack Overflow
🌐
CodeMag
codemag.com › Article › 1405000 › Node.js-Succinctly
Learn to Use an Array Object in Node.js; an Excerpt from Note.js Succinctly
Node.js provides an Array object for collection manipulation. In general, a Node.js Array object has the same behavior with a JavaScript Array object.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array
Array - JavaScript - MDN Web Docs
July 28, 2026 - The Array object, as with arrays in other programming languages, enables storing a collection of multiple items under a single variable name, and has members for performing common array operations.
Discussions

Array in Node.js, how to work with it - javascript
I'm a newbye in web programming and even more in Javascript, but I'm trying to learn it as I learn Node.js, and I found this strange error... I've got this code: var structobject = function(type,... More on stackoverflow.com
🌐 stackoverflow.com
How to add items to array in nodejs - javascript
pythonjavascriptc#reactjsjavaandroidhtmlflutterc++node.jstypescriptcssrphpangularnext.jsspring-bootmachine-learningsqlexceliosazuredocker ... Next You’ll be prompted to create an account to view your personalized homepage. Find centralized, trusted content and collaborate around the technologies you use most. Learn more about Collectives ... Save this question. Show activity on this post. How do I iterate through an existing array ... More on stackoverflow.com
🌐 stackoverflow.com
How to create array of object in node.js - javascript
pythonjavascriptc#reactjsjavaa...gularnext.jsspring-bootmachine-learningsqlexceliosazuredocker ... Next You’ll be prompted to create an account to view your personalized homepage. Find centralized, trusted content and collaborate around the technologies you use most. Learn more about Collectives ... Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... Save this question. Show activity on this post. ... I'm trying to create an array of objects, ... More on stackoverflow.com
🌐 stackoverflow.com
How to access node JS array in javascript? - JavaScript - SitePoint Forums | Web Development & Design Community
In my Node JS application I’m returning response to index html page like this res.render('index', {items:masterArray}); in index html page, I just want to give a alert for items[1] using javascript. how to do this in javascript ? alert(items[1]) // does not work what is the correct syntax ? More on sitepoint.com
🌐 sitepoint.com
0
December 22, 2018
🌐
Java2s
java2s.com › Tutorials › Javascript › Node.js_Tutorial › 0080__Node.js_Arrays.htm
Node.js Tutorial - Node.js Arrays
Index of /Tutorials · Parent Directory · Android.zip · Android/ · AndroidImage/ · AngularJS/ · AngularJSDemo/ · Bootstrap/ · BootstrapDemo/ · CImage/
🌐
Mixu
book.mixu.net › node › ch5.html
5. Arrays, Objects, Functions and JSON - Mixu's Node book
Arrays are ordered - the order in which you add items (e.g. push/pop or shift/unshift) matters.
🌐
GitHub
github.com › supercharge › arrays
GitHub - supercharge/arrays: Array utilities for Node.js
The @supercharge/arrays package provides chainable array utilities for Node.js and JavaScript.
Author: supercharge
🌐
npm
npmjs.com › package › array
array - npm
February 12, 2014 - Return an array. If array contains objects that implement ,toJSON(), array.js will call obj.toJSON() on each item.
      » npm install array
    
Published: Feb 12, 2014
Version: 0.4.3
Author: matthew mueller
Find elsewhere
🌐
Medium
sunilrana123.medium.com › nodejs-array-operations-b5f62d13369f
Nodejs: Array operations. In Node.js, you can perform various… | by Sunil Kumar | Medium
March 20, 2023 - In Node.js, you can perform various operations on arrays, such as adding or removing elements, iterating over the array, and transforming…
Top answer
1 of 2
2

You need to push a newly created item to your array like below:

CoinArray.push(new Coin.Create('123)); 

On the other hand if you want to create an object with keys ids and values corresponding Coin objects, you should try this:

CoinDictionary = {};
CoinDictionary['123'] = new Coin.Create('123');

Note:

I think that you should refactor a bit the Coin if you want to use it as a constructor function:

function Coin(id){
    this.id = id;
}

Doing this change you can use it as below:

CoinArray.push(new Coin('123'));

function Coin(id){
    this.id = id;
}

var CoinArray = [];
CoinArray.push(new Coin('123'));
CoinArray.push(new Coin('456'));
CoinArray.push(new Coin('789'));

console.log(CoinArray);
Run code snippetEdit code snippet Hide Results Copy to answer Expand

Update

At the end I want to have array with object and for example I will take first el of array, and execute other method from Coin class.

For this purpose If I were you I would have gone with the creation of an object with keys the ids and values references to Coin objects:

function Coin(id){
    this.id = id;
}

Coin.prototype.start = function(){
    console.log("game with id "+this.id+" started.");
}

Coins = {}
Coins['123'] = new Coin('123');
Coins['456'] = new Coin('456');
Coins['789'] = new Coin('789');

Coins['456'].start();
Run code snippetEdit code snippet Hide Results Copy to answer Expand

2 of 2
2
class Coin {
  constructor(id) {
    this._id = id;
  }
  start() {
    console.log('starting');
  }
}

CoinArray = [];
CoinArray['123'] = new Coin(123);
CoinArray['333'] = new Coin(333);
CoinArray['123'].start();

Also i would suggest managing id's that way:

let id = 0;
class Coin {
  constructor() {
    this._id = id++;
  }
  start() {
    console.log('starting');
  }
}

CoinArray = [];
CoinArray.push(new Coin());
CoinArray.push(new Coin());
CoinArray[0].start();
🌐
Medium
medium.com › @nailsonisrael › 11-tips-to-improve-your-ability-to-manipulate-arrays-using-node-js-89d09771a477
11 Tips to improve your ability to manipulate arrays using Node.js | by Nailson Israel | Medium
March 8, 2025 - I bet you already know that Node.js is based on JavaScript, which makes learning it much easier! We can use the unshift method. For example, let’s add three numbers before the number one! ... Using the array length: You can add a new element to the last position by assigning a value to the index equal to the current array size.
🌐
Techquestworld
techquestworld.com › home › blog › 10 essential array methods every node.js developer should know
10 Essential Array Methods Every Node.js Developer Should Know
March 17, 2026 - A complete guide to the 10 most useful array methods in Node.js— with examples, code snippets and performance tips for modern JavaScript development.
🌐
SitePoint
sitepoint.com › javascript
How to access node JS array in javascript? - JavaScript - SitePoint Forums | Web Development & Design Community
December 22, 2018 - In my Node JS application I’m returning response to index html page like this res.render('index', {items:masterArray}); in index html page, I just want to give a alert for items[1] using javascript. how to do this i…
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-arrays
JavaScript Arrays - GeeksforGeeks
// Creating an Array and Initializing with Values let a = ["HTML", "CSS", "JS"]; // Add Element to the end of Array a.push("Node.js"); // Add Element to the beginning a.unshift("Web Development"); console.log(a); To remove the elements from an array we have different methods like pop(), shift(), or splice().
Published: August 31, 2026
Top answer
1 of 8
138

You can use Array.forEach

var myArray = ['1','2',3,4]

myArray.forEach(function(value){
  console.log(value);
});
Run code snippetEdit code snippet Hide Results Copy to answer Expand

2 of 8
76

What you probably want is for...of, a relatively new construct built for the express purpose of enumerating the values of iterable objects... as distinct from for...in, which enumerates property names (presumably1 numeric indices in the case of arrays). Your loop displayed unexpected results because you didn't use the property names to get the corresponding values via bracket notation... but you could have.

const array = ["a","b","c","d"];

for (let value of array) {
  console.log(value);
}

for (let propertyName in array) {
  let value = array[propertyName];
  console.log("propertyName: %o, value: %o", propertyName, value);
}
<!------------------------------------------------------------------------------><script src="https://gh-canon.github.io/stack-snippet-console/console.min.js"></script><script>console.config({timeStamps:false,maximize:true})</script>
Run code snippetEdit code snippet Hide Results Copy to answer Expand

1 Unfortunately, someone may have added enumerable properties to the array or its prototype chain which are not numeric indices... or they may have assigned an index leaving unassigned indices in the interim range. The issues are explained pretty well here. The main takeaway is that it's best to loop explicitly from 0 to array.length - 1 rather than using for...in.

To address your comment (emphasis mine):

[...] why do I need to calculate the size of an array whereas the interpreter can know it[?]

Array.length is not calculated on the fly; it's updated whenever the length of the array changes. You're not going to see performance gains by avoiding it (apart from caching its value rather than repeatedly accessing the property). Here's a test of various constructs used to perform a sum operation on an array of 1,000 numeric elements (bigger bars are better).

Feel free to fork the test and try different inputs, methods, etc.

🌐
W3Schools
w3schools.com › js › js_arrays.asp
JavaScript Arrays
JS Examples JS HTML DOM JS HTML Input JS HTML Objects JS HTML Events JS Browser JS Editor JS Exercises JS Quiz JS Website JS Syllabus JS Study Plan JS Interview Prep JS Certificate ... An Array is an object type designed for storing data collections.
🌐
Reddit
reddit.com › r/node › processing an array of million of elements using node js.
r/node on Reddit: Processing an array of million of elements using node js.
February 27, 2019 -

Can we process an array of million elements using node js? (assume if there are inner loops also)

My findings are

  1. It may block the eventloop and freezes the server.

  2. Memmory must be explicitly increased for the V8's heap.

Is that good practice ? Is my findings are valid ?