简体   繁体   English

如何以降序(反向)顺序访问javascript数组?

[英]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. MySQL 给出降序结果集,但这个 for 循环首先打印第一个 id 元素。

You can either do from reverse length.你可以从反向长度做。

or或者

You can just reverse() the array你可以只reverse()数组

 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]); }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将KnockoutJS数组项反向排序,以便它们按降序添加到屏幕顶部 - How do I reverse order KnockoutJS array items so they are added to the top of the screen in descending order 如何按嵌套值降序排列这个 javascript 数组? - How to sort this javascript array in descending order by nested values? 按降序对Javascript关联数组值进行排序 - Sorting Javascript associative array values in descending order 订单数组如何按日期和时间降序? - How order array descending by date and time? 如何按降序返回多维数组? - How to return a multidimensional array of numbers in descending order? JavaScript的降序列表 - Descending order list of JavaScript 如何找到在javascript中按降序对数字数组进行排序所需的最小交换次数 - How to find the Minimum number of swaps required for sorting an array of numbers in descending order in javascript 如何对 javascript 数组进行排序,其中第一个记录应该是特定的,然后按降序排列 - How to sort javascript array where first record should be specific and then follow by descending order 如何制作一个 function 排序并返回 javascript 中数组中重复次数最多的值? - How to make a function that sorts and returns the most repeated value of array in descending order in javascript? 如何反转 Javascript 中的数组? - How to reverse an array in Javascript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM