📜  每个 javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:59.303000             🧑  作者: Mango

代码示例6
function each(collection, action) {
  if (Array.isArray(collection)) {
    for (var i = 0; i < collection.length; i++) {
      action(collection[i], i, collection);
    }
  } else {
    for (var key in collection) {
      action(collection[key], key, collection);
    }
  }
}