user7614902
user7614902

Reputation: 11

how to access javascript array in descending(reverse) order?

var content1    =  eval ("(" + data + ")");
var content    =  content1.Data;  
for (property in content) {console.log(content[property].name); }

I need to access this content array descending order. now it's work fine but not the way I want.It print first element in the array.

I want to print last element in first place. MySQL gives descending order result set but this for loop print first id element in first place.

Upvotes: 1

Views: 88

Answers (1)

A. L
A. L

Reputation: 12669

You can either do from reverse length.

or

You can just reverse() the array

var array = [1,2,3];

for (var item of array.reverse())
{
  console.log(item);
}

console.log(" ");


var other = ["first", "second", "third"];

for (var i = other.length - 1; i >= 0; i--)
{
  console.log(other[i]);
}

Upvotes: 1

Related Questions