Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

js array 0 to n

const range = ({
  from = 0,
  to,
  step = 1,
  length = Math.ceil((to - from) / step),
}) => {
  return Array.from({ length }, (_, i) => from + i * step);
};

console.log(
  range({length: 5}), // [0, 1, 2, 3, 4]
  range({to: 5}),    // [0, 1, 2, 3, 4]
  range({from: 2, to: 5}),    // [2, 3, 4] (inclusive `from`, exclusive `to`)
  range({from: 2, length: 4}), // [2, 3, 4, 5]
  range({from: 1, to: 5, step: 2}), // [1, 3]
  range({from: 1, to: 6, step: 2}), // [1, 3, 5]
)
Comment

PREVIOUS NEXT
Code Example
Javascript :: upload files with angular 
Javascript :: javascript write to firebase 
Javascript :: foreach loop js arrow functons 
Javascript :: move element to the top of list javascript 
Javascript :: js local storage 
Javascript :: axios api post request 
Javascript :: usememo hook react 
Javascript :: isfunction javascript 
Javascript :: how to see if user on phone 
Javascript :: lodash merge 
Javascript :: javascript remove duplicate objects from array es6 
Javascript :: javascript convert number to spreadsheet column 
Javascript :: Material-UI: A component is changing the default value state of an uncontrolled Select after being initialized. To suppress this warning opt to use a controlled Select. 
Javascript :: regex check if number is greater than 
Javascript :: js default parameter 
Javascript :: fibonacci series with recursion in javascript 
Javascript :: fontsize javascript 
Javascript :: get all date between two dates in javascript 
Javascript :: kendo datasource get 
Javascript :: async wait for axios reactjs 
Javascript :: javascript sleep 1 second" 
Javascript :: navlink 
Javascript :: onpress setstate react native 
Javascript :: cors error in node js express 
Javascript :: run react app 
Javascript :: ng-pick-datetime 
Javascript :: antd tag 
Javascript :: how-to-reset-a-form-using-jquery 
Javascript :: base 2 number javascript 
Javascript :: how to install nide js in ubuntu 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =