gpt4 book ai didi

javascript - 反转存储在 javascript 变量中的 JSON 数组

转载 作者:搜寻专家 更新时间:2023-11-01 04:44:22 25 4
gpt4 key购买 nike

我有一个 json 数组存储在以下格式的变量中:

{"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": 
[ {"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"}
]}

我怎样才能做到这一点。

enter image description here

最佳答案

使用数组reverse Javascript 的方法:

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

关于javascript - 反转存储在 javascript 变量中的 JSON 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21702805/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com