LoginSignup
3
2

More than 5 years have passed since last update.

JavaScriptのforEach

Posted at

概要

サンプル1

ソース

["apple", "orange", "pine"].forEach(function(item, index){
    console.log(index + ":" + item);
});

結果

0:apple
1:orange
2:pine

サンプル2

ソース

const maps = [
    {key: "k1", val: "value1"},
    {key: "k2", val: "value2"},
    {key: "k3", val: "value3"},
];
maps.forEach(function(item, index){
    console.log(index + ":" + item["key"] + "=" + item["val"]);
});

結果

0:k1=value1
1:k2=value2
2:k3=value3
3
2
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
3
2