我有这个JSON数组:
"locations": {
"0": {
"locationNo": "10014",
"inventoryLocationNo": "10014"
},
"1": {
"locationNo": "10499",
"inventoryLocationNo": "10499"
},
"2": {
"locationNo": "110868",
"inventoryLocationNo": "110868"
},
我想从此数组中删除此索引部分("0", "1", "2")
,其余全部应该相同。
有什么建议吗?
响应应该是这样的:
"locations": {
{
"locationNo": "13137",
"inventoryLocationNo": "13137"
},
{
"locationNo": "15857",
"inventoryLocationNo": "15857"
},
{
"locationNo": "15903",
"inventoryLocationNo": "15903"
},
答案 0 :(得分:8)
使用Object.values
:
var obj = {
"locations": {
"0": {
"locationNo": "10014",
"inventoryLocationNo": "10014"
},
"1": {
"locationNo": "10499",
"inventoryLocationNo": "10499"
},
"2": {
"locationNo": "110868",
"inventoryLocationNo": "110868"
}
}
};
obj.locations = Object.values(obj.locations);
console.log(obj);

或Object.keys
如果您不能使用Object.values:
var obj = {
"locations": {
"0": {
"locationNo": "10014",
"inventoryLocationNo": "10014"
},
"1": {
"locationNo": "10499",
"inventoryLocationNo": "10499"
},
"2": {
"locationNo": "110868",
"inventoryLocationNo": "110868"
}
}
};
obj.locations = Object.keys(obj.locations).map(key => obj.locations[key]);
console.log(obj);

答案 1 :(得分:0)
使用传播运算符的简单方法
import pandas as pd
time_range = pd.date_range("2018-01-01", "2018-02-01", freq='W')
print(time_range)
DatetimeIndex(['2018-01-07', '2018-01-14', '2018-01-21', '2018-01-28'], dtype='datetime64[ns]', freq='W-SUN')