Hızlı yanıt: kod örneği
Note: This answer is hopelessly out-of-date. For a more modern approach, look at the methods available on an array. Methods of interest might be:-loop:Note, however, that this approach is only good if you have a dense array, and each index is occupied by an element. If the array is sparse, then you can run into performance problems with this approach, since you will iterate over a lot of indices that do not really exist in the array. In this case, a -loop might be a better idea. However, you must use the appropriate safeguards to ensure that only the desired properties of the array (that is, the array elements) are acted upon, since the -loop will also be enumerated in legacy browsers, or if the additional properties are defined as .In ECMAScript 5 there will be a forEach method on the array prototype, but it is not supported in legacy browsers. So to be able to use it consistently you must either have an environment that supports it (for example, Node.js for server side JavaScript), or use a "Polyfill". The Polyfill for this functionality is, however, trivial and since it makes the code easier to read, it is a good polyfill to include.
- forEach
- map
- filter
- zip
- reduce
- every
- some
for
var length = arr.length, element = null;for (var i = 0; i < length; i++) { element = arr[i]; // Do something with element}
for .. in
for..in
enumerable