vue如何将对象中属性值为“”,null,undefined的属性去掉,组成一个新对象

在我们前后端联调的过程中,一系列的参数去后端查询接口,为了提升查询速度,前端需要把字段为空"",null,undefined,参数给去掉,那么我们就可以使用以下方法:

function removeEmptyProperties(obj) {

const newObj = {};

for (const key in obj) {

if (obj.hasOwnProperty(key) && objkey !== undefined && objkey !== null) {

newObjkey = objkey;

}

}

return newObj;

}

const originalObject = {

type: "book",

user: "Alice",

storeName: undefined,

storeId: undefined,

storeData: "",

storeDataId: null,

};

const objectWithoutEmptyProperties = removeEmptyProperties(originalObject);

console.log(objectWithoutEmptyProperties);

// 输出: { type: 'book', user: 'Alice', tenantId: '123' }

相关推荐
特创数字科技43 分钟前
一个纯本地运行的图片处理工具:压缩 / 裁剪 / 九宫格 / 圆角 / 滤镜 / 拼图 / 水印,终生使用
前端
IT_陈寒1 小时前
Vue的v-if和v-for混用居然是个天坑
前端·人工智能·后端
天衍四九-1 小时前
【无标题】
前端·spring boot·mysql·nginx·docker
广州华水科技1 小时前
2026年单北斗GNSS变形监测系统推荐榜单,解锁GNSS位移监测新高度
前端
xcyxiner2 小时前
DicomViewer24 修复编译bug(window test 失败)
前端·qt
linux_cfan2 小时前
videojs v10 源代码系列解读:34 · `createComposition`:类型安全的冲突检测
前端·安全
Bruce_Liuxiaowei3 小时前
网页版 DeepSeek “harness desktop“ WebGL 上下文创建失败排查实录
开发语言·javascript·webgl
utmhikari3 小时前
【AI原生】借助AI之力优化个人博客前端样式
前端·css·hexo·next·个人博客·ai-native·vibe coding
小凯在掘金4 小时前
为什么箭头函数不能作为构造函数?
前端·javascript