我刚接触Angular框架。当我想在Angular中迭代JSON对象时,我使用了JavaScript的
后来我知道Angular本身有一个
如何比较
为什么我们应该使用
请给我一些使用它的例子和理由,以展示其性能。
谢谢 :)
forEach
和for..in
循环。后来我知道Angular本身有一个
angular.forEach
循环来迭代对象。如何比较
angular.forEach
与JavaScript的for..in
和forEach
循环的性能?为什么我们应该使用
angular.forEach
而不是JavaScript的forEach
和for..in
?请给我一些使用它的例子和理由,以展示其性能。
谢谢 :)
if (!Array.forEach) {
应该改成if (!Array.prototype.forEach) {
。在这种情况下,!Array.forEach
总是为true
。而且,forEach
方法应该被调用在prototype
属性中。 - user5066707angular.forEach
的性能比普通的for/foreach
更好吗? - Vikas Bansal