Answer the question
In order to leave comments, you need to log in
NodeJS dynamically adding to array
Colleagues, tell me how to do the following more elegantly:
The code below is absolutely not working even in theory, but it clearly explains what I want:
Conditions:
some_hash - must be an object (NOT an array)
The code must turn into an “endless loop”
var some_hash={'1','2','3'}
for(var key in some_hash){
some_hash.push(key+1);
}
Answer the question
In order to leave comments, you need to log in
var names = Object.getOwnPropertyNames(obj);
for (var i = 0, len = names.length; i < len; ++i)
{
obj['prop' + i] = i;
names = Object.getOwnPropertyNames(obj);
len = names.length;
}
Use recursion.
I just don't understand why you need this? Do you want all Habr users to get node.js or browsers freeze?
For the sake of laughter, I wrote this in the FF console - as it should be, he ate one core.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question