var obj ={ "dependencies": { "axios": "^0.27.2", "lodash": "^4.17.21", "nanoid": "^4.0.0", "normalize.css": "^8.0.1", "pinia": "^2.0.18", "qs": "^6.11.0", "vant": "^3.5.4", "vue": "^3.2.37", "vue-router": "^4.1.3" }, "devDependencies": { "@vitejs/plugin-vue": "^3.0.3", "typescript": "^4.6.4", "vite": "^3.0.7", "vue-tsc": "^0.39.5" } } const iResult = {} for (var key in obj){ var objItem = obj[key] console.log(objItem) for (var item in objItem) { console.log(item) console.log(iResult[key]) !iResult[key] && (iResult[key] = [])// 这里的意思是不存在直接赋值为数组 { iResult[key].push(item) } } } iResultView Code
标签:iResult,vue,提取,objItem,js,var,key,字符串,console From: https://www.cnblogs.com/Insist-Y/p/16596687.html