-2
Good morning, everyone! I have a question about formatting an array in javascript.
My code is that way.
var oidup = ['5006144', '5006146']; //valores oid especifica
var oids = ['1.3.6.1.2.1.31.1.1.1.18.', '1.3.6.1.2.1.10.127.1.1.4.1.5.']; //propriedades oid para metrica
var oidtotal = []; // array
var j = 0;
var k = 0;
var z = 0;
for (j = 0; j < oids.length; j++) {
for (k = 0; k < oids.length; k++) {
oidtotal[z] = [oids[j] + oidup[k]];
z += 1;
}
}
console.log(oidtotal);
it returns me the values as follows.
oidtotal = [
[ '1.3.6.1.2.1.31.1.1.1.18.5006144' ],
[ '1.3.6.1.2.1.31.1.1.1.18.5006146' ],
[ '1.3.6.1.2.1.10.127.1.1.4.1.5.5006144' ],
[ '1.3.6.1.2.1.10.127.1.1.4.1.5.5006146' ]
]
I’m trying to format it so it would return me this way.
oidtotal = ['1.3.6.1.2.1.31.1.1.1.18.5006144','1.3.6.1.2.1.31.1.1.1.18.5006146','1.3.6.1.2.1.10.127.1.1.4.1.5.5006144','1.3.6.1.2.1.10.127.1.1.4.1.5.5006146']
Can you help me to understand how I can do this?
I tried to create a new array, and use the Join method, but could not get the expected result. I tried to accomplish it that way.
formataroid[0] = oidtotal.join(['\',\'']);
But that was the result.
formtaroid = [
"1.3.6.1.2.1.31.1.1.1.18.5006144','1.3.6.1.2.1.31.1.1.1.18.5006146','1.3.6.1.2.1.10.127.1.1.4.1.5.5006144','1.3.6.1.2.1.10.127.1.1.4.1.5.5006146"
]
I am trying to use the net-snmp module and the method session.get(formataroid, function(error, varbinds)
And it accepts string only. As it is in the doc https://www.npmjs.com/package/net-snmp
From now on, thank you very much.
Okay, we have the code, but could you please try to explain verbatim the purpose of the code? I can guess (and try to guess), but without a more formal description it’s kind of hard to be sure. Anyway, click [Edit] to add this information to your question.
– Luiz Felipe
Where is
oidtotal[z] = [oids[j] + oidup[k]];
swap foroidtotal += oids[j] + oidup[k];
, I guess that’s it.– Augusto Vasques
Good afternoon Luiz, I already put the description, thank you very much. Augusto, that way it doesn’t work, because it returns me without the apostrophe and the comma at the end of each Indice. Dessa forma me retorna assim:

oidtotal = 1.3.6.1.2.1.31.1.1.1.18.50061441.3.6.1.2.1.31.1.1.1.18.50061461.3.6.1.2.1.10.127.1.1.4.1.5.50061441.3.6.1.2.1.10.127.1.1.4.1.5.5006146
– Bruno D Angelo Silva