---
title: JavaScript – Optimize Loops – UI Policy scriptFalse
description: "Impact Area Performance Severity Warning Affected Element UI Policy ## Rule number **SN-0329** ## Impact Evaluating the length of an array each time it is iterated through is inefficient. ## Remediation Store the length of the array in a variable…"
url: "https://community-staging.qualityclouds.com/qcdocs/qc/javascript-rules-rules-for-servicenow/javascript-optimize-loops-ui-policy-scriptfalse/"
updated: "2025-03-21"
category: Best Practices Rules / JavaScript Rules
---

# JavaScript – Optimize Loops – UI Policy scriptFalse

Impact Area

Performance

           Severity

Warning

           Affected Element

UI Policy

## Rule number

**SN-0329**

## Impact

Evaluating the length of an array each time it is iterated through is inefficient.

## Remediation

Store the length of the array in a variable and use the variable in the evaluation statement.

### Time to fix

10 min

## Code examples

### Noncompliant code

var names = [‘George’, ‘Ringo’, ‘Paul’, ‘John’]; for(var i=0;i<names.length;i++){ doSomethingWith(names[i]); }

### Compliant code

var names = [‘George’, ‘Ringo’, ‘Paul’, ‘John’]; for(var i=0,j=names.length;i<j;i++){ doSomethingWith(names[i]); }
