您好,欢迎来到花图问答。
搜索
您的当前位置:首页angular.forEach()

angular.forEach()

来源:花图问答

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

本文如未解决您的问题请添加抖音号:51dongshi(抖音搜索懂视),直接咨询即可。

热门图文

Copyright © 2019-2025 huatuowenda.com 版权所有 湘ICP备2023022495号-1

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务