-1

I want to Write a program that prints numbers from 1 to 1000 Using For Loop. All numbers should be printed in the same line separated by comma and space (like this: 1, 2, 3).but i cant figure it out how to do it in for loop I am a beginner please help.

Muhammad Junaid
  • 180
  • 1
  • 11

1 Answers1

2

You can try the Spread syntax to create the array and then use keys to join with Array.prototype.join():

console.log([...Array(1000).keys()].join(', '));

OR: You can use Array.from() method which creates a new, shallow-copied Array instance from an array-like or iterable object:

console.log(Array.from(Array(1000).keys()).join(', '));
Mamun
  • 66,969
  • 9
  • 47
  • 59