> For the complete documentation index, see [llms.txt](https://algorithm.prettylog.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://algorithm.prettylog.com/algorithm-problems/algoexpert/medium/array-of-products.md).

# Array of Products

![](/files/iVnDGXEFw8n7D8nkY4Gt)

* N, N

```jsx
function arrayOfProducts(arr) {
  const products = new Array(arr.length).fill(1);

  for (let i = 1; i < arr.length; i++) {
    products[i] = products[i - 1];
    products[i] *= arr[i - 1];
  }

  let runningProduct = 1;
  for (let i = arr.length - 1; i >= 0; --i) {
    products[i] *= runningProduct;
    runningProduct *= arr[i];
  }

  return products;
}

// Do not edit the line below.
exports.arrayOfProducts = arrayOfProducts;
```
