Dynamic object array

javascript

Solution

You don't have to make it dynamic, it already is. You merely need to add more objects onto the array:

// Add some new objects
objectArray.push({});
objectArray.push({});
console.log(objectArray.length); // 5

// Remove the last one
objectArray.pop();
console.log(objectArray.length); // 4

In JavaScript, array lengths need not be declared. They're always dynamic.

You can modify the individual objects by array key:

// Add a property to the second object:
objectArray[1].newProperty = "a new property value!";

Problem

In javascript we have array with static number of objects. ``` objectArray = [{}, {}, {}]; ``` Can someone please explain to me how can I make this number dynamical?

Original source