- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the use of _.size() method in JavaScript?
_.size()
_.Size() is from the underscore.js library of javascript. This is used to find the size of an array. One should make sure that before using this method one should use the CDN of the underscore.js to execute the code.
syntax
_.size(array);
Example-1
In the following example, a normal array is passed into _.size() method to get the size of the array.
<html> <body> <head> <script src = "https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js"> </script> </head> <body> <script type="text/javascript"> var arr = [100, 62, 73, 534, 565]; document.write(_.size(arr)); </script> </body> </html>
Output
5
Example-2
In the following example, an array that consists of object elements is sent into _.size() method to find the size.
<html> <body> <head> <script src ="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js"> </script> </head> <body> <script type="text/javascript"> var arr = [{name:"Anu", age: 25}, {name:"uday", age: 29}, {name:"Anusha", age: 23}]; document.write(_.size(arr)); </script> </body> </html>
Output
3
Advertisements
To Continue Learning Please Login
Login with Google