over 9 years ago
Objects are another powerful way of handling and storing of data. In arrays the indexes are commonly numerical; objects give us a better way of assigning and retrieving data.
- <html>
- <script type="text/javascript">
- /* Declare Object*/
- var detail = new object();
- /* initialize the array */
- detail.firstname = 'naveen';
- detail.lastname = 'kumar';
- detail.email = 'xxx@hotmail.com';
- detail.getFullDetail = function(){
- alert(detail.firstname+ ' '+ detail.lastname + ' '+ detail.email);
- }
- detail.getFullDetail();
- </script>
- </html>
<html> <script type="text/javascript"> /* Declare Object*/ var detail = new object(); /* initialize the array */ detail.firstname = 'naveen'; detail.lastname = 'kumar'; detail.email = 'xxx@hotmail.com'; detail.getFullDetail = function(){ alert(detail.firstname+ ' '+ detail.lastname + ' '+ detail.email); } detail.getFullDetail(); </script> </html>
Another way of creating an object is by using the curly braces.
- <html>
- <script type="text/javascript">
- /* Declare Object*/
- var detail = {
- 'firstname':'naveen',
- 'lastname':'kumar',
- 'email':'xxx@hotmail.com',
- 'getFullDetail' = function(){
- alert(this.firstname+ ' '+ this.lastname + ' '+ this.email);
- }
- detail.getFullDetail();
- </script>
- </html>
<html> <script type="text/javascript"> /* Declare Object*/ var detail = { 'firstname':'naveen', 'lastname':'kumar', 'email':'xxx@hotmail.com', 'getFullDetail' = function(){ alert(this.firstname+ ' '+ this.lastname + ' '+ this.email); } detail.getFullDetail(); </script> </html>
Thanks
Can you help out the community by solving one of the following Javascript problems?
Do activity (Answer, Blog) > Earn Rep Points > Improve Rank > Get more opportunities to work and get paid!
For more topics, questions and answers, please visit the Tech Q&A page.
0 Comment(s)