反向存储在JavaScript变量的JSON数组

反向存储在JavaScript变量的JSON数组

本文介绍了反向存储在JavaScript变量的JSON数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有存储在变量格式如下JSON数组:

I have a json array stored in variable in format below:

{"info":
[ {"typeid": "877", "recid": "10", "repeaterid": "0",  "pageid": "26966", "maxrecords": "1"},
  {"typeid": "877", "recid": "11", "repeaterid": "0",  "pageid": "26966", "maxrecords": "1"},
  {"typeid": "459", "recid": "3", "repeaterid": "0",  "pageid": "26966", "maxrecords": "1"},
  {"typeid": "459", "recid": "4", "repeaterid": "0",  "pageid": "26966", "maxrecords": "1"},
  {"typeid": "456", "recid": "5", "repeaterid": "0",  "pageid": "26966", "maxrecords": "1"},
  {"typeid": "456", "recid": "6", "repeaterid": "0",  "pageid": "26966", "maxrecords": "1"}
]}

我要扭转内JSON数组info.Like此

I want to reverse the inner JSON array for info.Like this

{"info":
[ {"typeid": "456", "recid": "6", "repeaterid": "0",  "pageid": "26966", "maxrecords": "1"},
  {"typeid": "456", "recid": "5", "repeaterid": "0",  "pageid": "26966", "maxrecords": "1"},
  {"typeid": "459", "recid": "4", "repeaterid": "0",  "pageid": "26966", "maxrecords": "1"},
  {"typeid": "459", "recid": "3", "repeaterid": "0",  "pageid": "26966", "maxrecords": "1"},
  {"typeid": "877", "recid": "11", "repeaterid": "0",  "pageid": "26966", "maxrecords": "1"},
  {"typeid": "877", "recid": "10", "repeaterid": "0",  "pageid": "26966", "maxrecords": "1"}
]}

我怎样才能做到这一点。

How can i achieve this.

推荐答案

使用数组 逆转 的Javascript方法:

Use the array reverse method of Javascript:

var objAssetSelection = $.parseJSON(strAssetSelection);
objAssetSelection.info.reverse();
console.log(objAssetSelection);

这篇关于反向存储在JavaScript变量的JSON数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 15:32