Hi dev,
In this article we will learn example about Create Array From Argument Range using javascript. Let's start …
Syntax & Example:
create-array-from-argument-range.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>create-array-from-argument-range</title>
<link rel="stylesheet" type="text/css" href="../style.css" />
</head>
<body>
<h1>17-create-array-from-argument-range!</h1>
<h3>Create an array of the values from the 'min' and 'max' (start & end) range provided</h3>
<script type="text/javascript" src="script.js"></script>
</body>
</html>
Syntax & Example:
script.js
console.log('17-create-array-from-argument-range');
function generateArrayFromRange(startNum, endNum) {
const rangeArray = [];
for(let curNum = startNum; curNum <= endNum; curNum++) {
// console.log('curNum: ', curNum);
rangeArray.push(curNum);
// console.log('rangeArray: ', rangeArray);
}
return rangeArray;
}
const range1 = generateArrayFromRange(1, 5);
console.log(range1);
console.log('----------');
const range2 = generateArrayFromRange(-5, 0);
console.log(range2);
Hope it can help you…
Categories : JavaScript
Tags : HTML