我将此对象作为响应对象
{
"data": [
{
"id": "203",
"bench": "abc"
},
{
"id": "205",
"bench": "def"
}
],
"responseCode": 200,
"isSuccess": "true"
}
现在我想在响应对象
之上添加此对象{
"id": "0",
"bench": "Select bench"
}
所以最终的对象应该是这样的
{
"data": [
{
"id": "0",
"bench": "Select bench"
},
{
"id": "203",
"bench": "abc"
},
{
"id": "205",
"bench": "def"
}
],
"responseCode": 200,
"isSuccess": "true"
}
有没有办法在打字稿中做到这一点?我试过'不合时宜',但它没有用。
答案 0 :(得分:0)
response = {
"data": [
{
"id": "203",
"bench": "abc"
},
{
"id": "205",
"bench": "def"
}
],
"responseCode": 200,
"isSuccess": "true"
};
response.data.unshift({
"id": "0",
"bench": "Select bench"
});
console.log(response); // shows json object