473,387 Members | 1,897 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Problem occurred while Prototyping Arrays

46
Hi all,

I am used prototype concept in javascript. But here i got a problem while printing arrays.

Expand|Select|Wrap|Line Numbers
  1. Array.prototype.count = function()
  2. {
  3.     Input = this;
  4.     document.writeln("<br>");
  5.     for ( key in Input )
  6.         document.writeln( "["+key+"]" + "=>" + Input[key] );
  7. }
  8.  
  9. var d = new Array(1,1,1,1,5,"adfasdfasdf");
  10. d.count();
The output look like
Expand|Select|Wrap|Line Numbers
  1. [0]=>1 
  2. [1]=>1 
  3. [2]=>1 
  4. [3]=>1 
  5. [4]=>5 
  6. [5]=>adfasdfasdf
  7. [count] = function() { Input = this; document.writeln("
  8. "); for ( key in Input ) document.writeln( "["+key+"]" + "=>" + Input[key] );}
It print the array content and it also print the native code.
Why it prints the native code?
Anything to suppress this printing of native code?
Dec 5 '07 #1
1 1016
mrhoo
428 256MB
When you add a property to an object, even if it is a native object, you are not adding native code.

A for in loop always returns user defined properties. Loop through an array using it's length and item indexes-

Expand|Select|Wrap|Line Numbers
  1. Array.prototype.count=function(){
  2.   var L= this.length,A= [];
  3.   for(var i= 0; i< L; i++) {
  4.         A[i]=(i+1)+ '. '+ this[i];
  5.    }
  6.   return A.join('\n');
  7. }
Dec 5 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

30
by: Dave Allison | last post by:
Oh no, not another "check out my cool new language" posting :-) For about 5 years now, I have been developing a scripting/prototyping language that is now available on the net. It's called...
6
by: busterama | last post by:
It's probably something simple, but I just can't find the solution. I'm using the javascript slideshow code at http://javascript.internet.com/miscellaneous/fading-slide-show.html for a slideshow...
3
by: ChrisWinterscheid | last post by:
We are running DB2 8.1 on AIX 5.2. DB2level shows: DB21085I Instance "db2inst1" uses "32" bits and DB2 code release "SQL08016" with level identifier "02070106". Informational tokens are "DB2...
13
by: rs | last post by:
Dear All, I have a question regarding proptypes for functions. What is the recommended practice? The way I do it is to put all my external functions in a header file, while protyping...
4
by: Tilted | last post by:
Does anyone here use prototyping tools? I'm building one myself as I feel like I'm doing the same thing over and over again with the majority of my projects, how do people generally feel about...
2
by: Chukkalove | last post by:
I'm sorry this message is so long. I have had to make some changes to an application written by a previous developer who used unmanaged serialization to store complex objects to file. The...
6
by: LaVic | last post by:
Hello Everyone, I am trying to add two binary numbers in the form of two arrays. The code that i have been using compiles, but it does not give me the results i would expect. The problem that i...
30
by: Einstein30000 | last post by:
Hi, in one of my php-scripts is the following query (with an already open db-connection): $q = "INSERT INTO main (name, img, descr, from, size, format, cat, host, link, date) VALUES ('$name',...
1
by: prasath03 | last post by:
Hi, I am struggling with the following problem. Can somebody pls help me?. I am developing a wesbite for user can edit their files only, so i am going to develop a page for a Tree Structure in...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.