Question: I'm trying to solve a code challenge on code wars and don't understand why I'm getting an error message regarding the `.length` of a string inside of an array when I try to run it. 

It's definitely the first `.length` in line 7. I've tried running other `arr[i].lengths` and they work, I'm thinking it's a problem with scope? 

```js
function longestConsec(strarr, k) {
  var arr = [];
  if (strarr.length == 0 || k > strarr.length || k <= 0) {
    return "";
  }
  for (var i = 1; i <= strarr.length; i++) {
    if (strarr[i].length > strarr[0].length && arr.length < k) {
      arr.push(strarr[i]);
    }
  }
  arr.join('');
}

longestConsec(["zone", "abigail", "theta", "form", "libe", "zas"], 2);
```

Should return `"abigailtheta"` as it's the 2 longest strings after the 
first string which were the requirements. 

> 
> VM304:7 Uncaught TypeError: Cannot read property 'length' of undefined
> 
> 
>

Answer: 
The elements in an array go from 0 to `length - 1`.

You have 6 strings in the array, the last one having the index 5.

Because the condition set that you should iterate while the index is lower or **equal** to `strarr.length` it tries to iterate the 6th element, which doesn't exist.

You should change the condition for the iteration:

```
for (var i = 1; i < strarr.length; i++) {

```

```js
function longestConsec(strarr, k) {
  var arr = [];
  if (strarr.length == 0 || k > strarr.length || k <= 0) {
    return "";
  }
  for (var i = 1; i < strarr.length; i++) {
    if (strarr[i].length > strarr[0].length && arr.length < k) {
      arr.push(strarr[i]);
    }
  }
  arr.join('');
  alert(arr);
}

longestConsec(["zone", "abigail", "theta", "form", "libe", "zas"], 2);
```
You’re iterating on the array with the wrong boundaries .

You should change it to strarr.length - 1.

Or remove the less than or equal and use only less than operator 

Because the index of the last accessible element in an array is the array length minus 1