0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Javascriptにrangeを入れる方法

Last updated at Posted at 2020-09-10

Nuxtjsプロジェクトにpythonのrange()のようなやつを入れたかったので以下のとおりで

utils.jsに

export function range(start, end) {
  /* generate a range : [start, start+1, ..., end-1, end] */
  const len = end - start + 1;
  const a = new Array(len);
  for (let i = 0; i < len; i++) a[i] = start + i;
  return a;
}

使うときは range(26, 52)
そのままcomponentに追加する時は
range(start, end) {
/* generate a range : [start, start+1, ..., end-1, end] */
const len = end - start + 1
const a = new Array(len)
for (let i = 0; i < len; i++) a[i] = start + i
return a
}
})

0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?