Click here to Skip to main content
13,047,567 members (60,487 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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 22:43pm
enhzflep 11-Apr-13 4:48am
The newest item will be the one with the highest index.

var lastItem = arrayObj[ arrayObj.length - 1];
Matej Hlatky 11-Apr-13 5:06am
Array Object has the length property, not size.
enhzflep 11-Apr-13 5:09am
fixed. Thanks.
umeshinator 11-Apr-13 5:12am
can u please explain a bit? thank you in advance
enhzflep 11-Apr-13 5:24am
Can I explain a bit about what?
umeshinator 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 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] ) );

Visis followed by


( do read, it's enlightening)
umeshinator 11-Apr-13 14:08pm
thankyou bro,but y u against w3schools..i thik w3schools preety gud
enhzflep 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 if they were in range)

1 solution

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

Solution 1

Try this:

var registeredElements = [];

// enter data in array

var LastArrayIndexValue = regManadatoryElements[regManadatoryElements.length];

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 16 Apr 2013
Copyright © CodeProject, 1999-2017
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