angular.forEach()

作者: 在路上_W | 来源:发表于2016-04-28 19:45 被阅读417次

angular.forEach()

angular.forEach(obj, iterator, [context]);
iterator(value, key, obj)

说明:

Invokes the iterator function once for each item in obj collection, which can be either an object or an array. The iterator function is invoked with iterator(value, key, obj),
where value is the value of an object property or an array element, key is the object property key or array element index and obj is the obj itself. Specifying a context for the function is optional.

理解:

forEach迭代对象或者数组。例如下面代码,value为values中的值,key为values中值对应的key,obj为对象本身。

参数:

Param Type Details
obj Object Array Object to iterate over.
iterator Function Iterator function.
context(optional) Object Object to become context (this) for the iterator function.

返回值:

Object: Reference to obj.
Array

example:

var values = {name: 'misko', gender: 'male'};
var log = [];
var tmpVal = angular.forEach(values, function(value, key, obj) { 
  this.push(key + ': ' + value);
}, log);
console.log(values);
console.log(log);
console.log(tmpVal);

result:

Object {name: "misko", gender: "male"}//values
["name: misko", "gender: male"]//log
Object {name: "misko", gender: "male"}//tmpVal

相关文章

  • angular

    jQuery.inArray() angular.forEach

  • angular.forEach()

    angular.forEach() 说明: Invokes the iterator function once ...

  • For循环的演变

    For循环,For In,For each,$Angular.forEach,$.grep 1. For循环 2....

  • angular中的forEach

    1、 普通数组中对象的使用 angular.forEach(arr,function(value,key){})举...

  • angularjs 循环调服务

    angularjs 循环调服务,因为服务是异步的,所以列举一下错误示范: angular.forEach(data...

网友评论

    本文标题:angular.forEach()

    本文链接:https://www.haomeiwen.com/subject/bjjhrttx.html