I want to get an output array beginning with min value and ending with max value => [5,6,7,8,9,10].
But I get only min value in new array => [5]. Why does this happen?
function arrayFromRange(min , max){
const newArray = [];
for( let x = min ; x <= max; x++ ){
newArray.push(x);
return newArray;
}
}
const newarray1 = arrayFromRange(5,10);
console.log(newarray1);
returning early (inside your loop rather than outside). Moev thereturn newArray;line outside of your loop and your function will work :)