Answer the question
In order to leave comments, you need to log in
How to output in a loop from 1 to 10 without using variables?
Good afternoon!
In a familiar situation, we would resort to something like this construction:
for(var i = 0; i < 10; i++ ){
console.log(i);
}
Answer the question
In order to leave comments, you need to log in
You can loop through the array:
Array.apply(null, {length: 10}).map(function(){console.log(1+arguments[1])})
This creates an empty array of 10 elements, which are set to undefined
, and for each, a function is called that displays the index of the element, increased by 1, so that not 0..9
, but 1..10
. (function f(){
console.log(arguments[0]);
if( arguments[0]<10) f(arguments[0]+1);
})(1)
But here the function itself is sort of like a variable.
Create an array with numbers from 0 - 10 by hand and output as a join
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question