다음이 시작 값이라고 가정해 보겠습니다. -
var startValue=10;
다음이 최종 가치라고 가정해 보겠습니다. −
var endValue=20;
for 루프를 사용하여 시작 값과 끝 값 사이의 숫자를 가져옵니다. -
예시
var startValue=10;
var endValue=20;
var total='';
function printAllValues(startValue,endValue){
for(var start=startValue;start < endValue ;start++){
total=total+start+",";
}
}
printAllValues(startValue,endValue)
var allSequences = total.slice(0, -1);
console.log(allSequences); 위의 프로그램을 실행하려면 다음 명령을 사용해야 합니다 -
node fileName.js.
여기에서 내 파일 이름은 demo87.js입니다.
출력
이것은 다음과 같은 출력을 생성합니다 -
PS C:\Users\Amit\JavaScript-code> node demo87.js 10,11,12,13,14,15,16,17,18,19