I am Hack Sparrow
Captain of the Internets.

JavaScript Array-like Objects

Have you heard about array-like objects in JavaScript? If no, this is a good post to learn about them. Array-like objects are not a separate object type, they are the same old object we are familiar with, except they 'look' like arrays. What do I mean by that? Let's find out. You might be familiar with the arguments variable which every JavaScript function has access to by default. We access its items using arguments[0], arguments[1] etc. Let's take a lo ...

JavaScript – Convert arguments to Array

All JavaScript functions have a local variable called arguments, which is a list of arguments that were passed to the executing function. The first argument can be accessed as arguments[0], the second one as arguments[1] etc. To find out the numbers of arguments you can do arguments.length. You can see arguments is a lot like an array. I say it is a lot like a ...

JavaScript – Check Object Types

There are times when you want to know the object type of an instance in JavaScript, whether it is an Array, or a Function, or an Object, a String etc. There are two flavors to doing that, one involves the use of the instanceof operator, the other involves stringification of the object's prototype. Follow the examples below, I show both the techniques. First create these variables: [code] var a = []; var o = {}; var s = ''; var n = 42; var f = function() {}; ...

JavaScript: get the number of properties in an object WITHOUT LOOPING

Unlike arrays, JavaScript objects do not a have a length property which gives you the number of properties / items in an object. The most common way of getting the number of properties is to loop through the object - not pretty, resource intensive. This had been a long known problem JavaScript developers have been facing for a long time. All modern and superior browsers support a fix for this a ...

Python: length or size of list, tuple, array

Let me clarify something at the beginning, by array, you probably mean list in Python. list is the equivalent of arrays in JavaScript or PHP. Arrays in Python is an altogether different thing. Ok, having cleared that, getting the the size of a list or tuple (or array, if you will), is pretty straighforward. You just call the l ...