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.

繰り返し処理

Posted at

each()

  • 繰り返し処理を記述する関数

HTML要素に対しての構文

HTML要素.each(function(index, element) {
    //繰り返し処理を記述する
})
$('li').each(function(index, element) {
    console.log(index + ': ' + $(element).text());
}) // 0: サンプル1
   // 1: サンプル2
   // 2: サンプル3

配列に対しての構文

HTML要素.each(function(index, value) {
    //繰り返し処理を記述する
})
const array = [4,7,1,8,5];
$.each(array, function(index, value) {
    console.log(index + ': ' + value);
}) // 0: 4
   // 1: 7
   // 2: 1
   // 3: 8
   // 4: 5

オブジェクトに対しての構文

$.each(obj, function(property, value) {
    console.log(property + ': ' + value);
})
0
0
0

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?