Bootstrap FreeKB - Node.js - Count the number of elements in a list using length
Node.js - Count the number of elements in a list using length

Updated:   |  Node.js articles

Here is an example of how you create a list of fruit. Check out my article FreeKB - Node.js - Getting Started with Lists for more details on Lists / Arrays.

length can be used to count the number of elements in the list.

const fruits = ["Apple", "Orange", "Banana", "Pineapple"];
console.log(`There are ${fruits.length} elements in the 'fruits' list`);


Which in this example should return 4.

~]$ node app.js
There are 4 elements in the 'fruits' list

 

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 4247a0 in the box below so that we can be sure you are a human.