Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Javascript HTML5
how to display the newest index of an array in javascript?
we enter multiple text in our textbox made in HTML,and that is stored
in array and we want those entered text to be displayed ,where newly entered has to be on top?
Posted 10-Apr-13 23:43pm
Comments
enhzflep at 11-Apr-13 4:48am
   
The newest item will be the one with the highest index.
 
var lastItem = arrayObj[ arrayObj.length - 1];
Matej Hlatky at 11-Apr-13 5:06am
   
Array Object has the length property, not size.
enhzflep at 11-Apr-13 5:09am
   
fixed. Thanks.
umeshinator at 11-Apr-13 5:12am
   
can u please explain a bit? thank you in advance
enhzflep at 11-Apr-13 5:24am
   
Can I explain a bit about what?
umeshinator at 11-Apr-13 5:33am
   
also,how to store the values in the array ?
i have created an array like this ,is it correct?
 
var msg = new array();
var lastitem = msg[msg.length -1];
enhzflep at 11-Apr-13 5:54am
   
It's close, but javascript is CaseSensitive. (array should be Array)
 
Here's a short demo:
function demoFunc()
{
var i, mArray = new Array();
for (i=0; i<10; i++)
mArray[ i ] = "Int: " + i;
 
for (i=0; i<10; i++)
mArray[ mArray.length ] = "Float: " + (0.5+i);

var ul = document.createElement('ul');
var len = mArray.length;
for (i=0; i<len; i++)
{
var li = document.createElement('li');
li.appendChild( document.createTextNode( mArray[i] ) );
ul.appendChild(li);
}
document.body.appendChild(ul);
}
 

Visis w3fools.com followed by w3schools.com
 
JavaScript/Reference/Global_Objects/Array
w3fools.com
w3schools.com
 
( do read w3fools.com, it's enlightening)
umeshinator at 11-Apr-13 14:08pm
   
thankyou bro,but y u against w3schools..i thik w3schools preety gud
enhzflep at 11-Apr-13 14:15pm
   
No worries mate.
 
Why I'm against w3schools?
I've noticed incomplete, trivial examples in far too many cases. I could go on and on and on, but the article I linked to will do a far better job than I can.
 
I've fixed the links in my above comment, and will repeat one.
 
I really suggest you read it. (I'd throw rocks at w3schools.com if they were in range)
 
www.w3fools.com

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Try this:
 
var registeredElements = [];
 

// enter data in array
 

var LastArrayIndexValue = regManadatoryElements[regManadatoryElements.length];
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Mathew Soji 334
1 Maciej Los 295
2 BillWoodruff 290
3 Afzaal Ahmad Zeeshan 257
4 DamithSL 225
0 OriginalGriff 6,369
1 Sergey Alexandrovich Kryukov 5,973
2 DamithSL 5,183
3 Manas Bhardwaj 4,673
4 Maciej Los 4,045


Advertise | Privacy | Mobile
Web01 | 2.8.1411019.1 | Last Updated 16 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100