What you want to see on DotNetFunda.com ?
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 8946 |  Welcome, Guest!   Register  Login
 Home > Forums > jQuery > Find length of Object using Jquery. ...
Nratz83

Find length of Object using Jquery.

Replies: 2 | Posted by: Nratz83 on 10/9/2012 | Category: jQuery Forums | Views: 537 | Status: [Member] | Points: 10  


Hi,

I would like to know, how can we get the length of an Object using jquery. I have tried using object.length property, but it gives me result as undefined.
Below is my code where i have been able to get the keys and their values, but what i am looking is to get the length of my object.

jQuery.each(c, function(name, value) { 

alert(name + ": " + value);
});


Any help is appreciated.

Thanks.


Reply | Reply with attachment | Alert Moderator

 Responses below this adGet hundreds of .NET Tips and Tricks videos

 Replies

Kanje_Ravi
Kanje_Ravi  
Posted on: 10/9/2012 1:01:06 PM
Level: Starter | Status: [Member] | Points: 25

Hi Nratz83 ,

As per your query i understand that you are looking to for loop an array or collection..please find the below block of code..may it help you..
Put it in your script block and check..


$(document).ready(function () //this function is needed to display on page load..
{
var test = new Array(); //declare an empty array
var test = new Array("Ravi", "Ramesh", "Rockesh"); //assign values to it
$.each(test, function (i) //for loop an array here i=index of an array
{
alert(test);
})
});


Thanks & Regards,
Ravindra M
(Success Always Depends on Dedication & Commitment)

Nratz83, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Devi0074u
Devi0074u  
Posted on: 3/12/2013 5:41:56 AM
Level: Starter | Status: [Member] | Points: 25

You can use length to get the length of any array.

e.g: new Array("A", "B", "C").length // will give you 3.

As you said object, which kind of object it is.
Is it a jSON string that you are trying to iterate?
In that case, you can use eval() / JSONStringify() to convert the string to jSON and then you can use length property .

Hope it will help you :)

Nratz83, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Reply - Please login to reply


Click here to login & reply

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/21/2013 11:17:56 PM