我有一个包含对象和数组的嵌套数据结构.如何提取信息,即访问特定或多个值(或键)?
例如:
var data = {
code: 42,
items: [{
id: 1,
name: 'foo'
}, {
id: 2,
name: 'bar'
}]
};
Run Code Online (Sandbox Code Playgroud)
我怎么能访问name第二项items?
例如
(async() => {
let apiRes = null;
try {
apiRes = await axios.get('https://silex.edgeprop.my/api/v1/a');
} catch (err) {
console.error(err);
} finally {
console.log(apiRes);
}
})();
Run Code Online (Sandbox Code Playgroud)
中的finally,apiRes将返回null。
即使api收到404响应,响应中仍然有一些我想使用的有用信息。
finally当axios引发错误时,如何使用错误响应。