Often times you get data from many different sources. It would be helpful to know the length of the data. That would help you determine whether to go in direction A or B. Learn to easily find the length of your data whether it’s a string, object or array.
Below is a simple and easy to use JavaScript function that will help you quickly find out the size of your data.
var size = function (collection)
{
var str = typeof(collection)
if(str ==="number" || str ==="string")
{
var d1 = str.toString()
return collection.toString().length
}
else if(str ==="object" || str ==="array")
{
return Object.keys(collection).length
}
}
Let’s suppose you have the following data:
var str = "123"
var obj = {a:2, b:2}
var arr = ["0", "1", "2",'arr']
To find out the length of each data type you would simply call it like this:
console.log( 'str -> ' + size(str) ) //--> str -> 3
console.log( 'obj -> ' + size(obj) ) //--> obj -> 2
console.log( 'arr -> ' + size(arr) ) //--> arr -> 4
Results for your:
Once you start using this function, you will start to see it will make your life a lot easier.
You spend weeks building a project.
Your client pays you.
Then the income stops.
Meanwhile, other developers are turning similar skills into products that generate revenue month after month.
A SaaS, plugin, web app, or digital product can continue bringing in customers long after it's launched.
The real question isn't whether you can build one.
It's how much money you're leaving on the table by not starting.
Learn How To Build Monthly Income →