I have an object that looks something like this.
var obj = {
speed: 10,
volume: 14,
aux_deform: 1.8,
energy: 21.5,
aux_energy: 0.2
}
There will be additional fields/properties added at runtime, so the object can contain any number of properties at any given time. As you can see in my object example, some properties can start with "aux_".
Now, I want to create another object from this one that contains only properties that start with "aux_".
The way I am doing it now is something like this.
var newObj = [];
for(prop in obj)
{
if (prop.startsWith('aux_'))
{
newObj[prop] = obj[prop];
}
}
Now I have a new object and I can do something like:
alert(newObj.aux_energy);
This works ok, but I am wondering if this is the right approach. Is there any easier way, or a more elegant way for what I am trying to achieve? Are there any (security or technical) issues/problems with this way of creating objects?
And the question from the title: is the newly created object actually an associative array with properties as keys (since it's created that way) or is there any difference.