I’ve been working a lot on my Superintendent project lately, and I just ran across an odd solution to a problem I was having. I’ve been writing the agent in Node.js, and I needed a way to get the output of /proc/meminfo into a clean, well-formatted JSON object. The issue I was having was I needed a way to assign object property names based on variables. Here’s what I mean:
var meminfo = new Object();
var someName = "objectPropertyName";
//now, assign an object property based on the variable
//someName's value
meminfo.someName = "some data here.";
You can probably already see the problem. The property that we assigned is called meminfo.someName, but we wanted it to be meminfo.objectPropertyName. How do we solve this? Well, first, let’s take a look at an associative array that would get the job done (albeit with an array):
var meminfo = new Array();
var someName = "arrayPropertyName";
//assign a value to the array with the key being the
//content of the variable 'someName'
meminfo[someName] = "some data here.";





