Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
541 views
in Technique[技术] by (71.8m points)

请问如何优雅的判断数组存在和数组长度

比如说后端接口返回了一个数组类型数据 前端要判断 (json.array && json.array.length) {} 更极端点可能要判断下类型 想知道有没有什么办法可以比较优雅的解决. 使用的技术栈有Vue TS Lodash


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

我觉得这就应该变成前后端开发的一种约定俗成。
数组类型的字段,后端无论如何就是应该返回一个数组。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...