DEV Community

Berra
Berra

Posted on

Javascript Arrays

Remember how to spell lentgh lenght length. It is very good when working with arrays in javascript.

You could also create a small helper function like this:

function size(arr) {
  return array.length;
}
Enter fullscreen mode Exit fullscreen mode

Size is much easier to spell than length. This will also work for strings.

Would like to know the size of an object? You could use our nice function to do this:

const obj = {
  keyA: "A",
  keyB: "B",
}

size(Object.keys(obj)); // 2
Enter fullscreen mode Exit fullscreen mode

That is sweet.

Hope you find this useful or funny. Until next time.

Top comments (0)