javascript - 如果所有数组的长度不同,如何将嵌套数组中的所有信息查询到dom?
问题描述
即使数组的长度不同,我如何输出特征类别?我已经能够使用 projects.features[1] 输出代码,但由于嵌套数组长度的大小不同,我不确定该怎么做。
const peet = document.querySelector('.projectInserts');
const projects = [
{"Title":"InstaJam",
"image":"img/ig.jpg",
"Gif":"gif-title",
"Github":"github",
"description":["first","second", "third"],
"features":["PHP / Laravel", "Html and CSS", "Blade", "Composer",
"User authentication", "MySQL"
],
"Link":"link",
"class": "app"
},
{"Title":"Kayak HTML Email",
"image":"img/kayak.png",
"Gif":"gif-title",
"Github":"github",
"description":["first","second", "third"],
"features":[
"User authentication", "MySQL"
],
"Link":"link"
},
解决方案
不太确定您想要什么,但这会将您的所有功能集中在一个阵列中。
let getIndividualFeatures = []
for(let i = 0; i < projects.length; i++){
getIndividualFeatures.push(projects[i].features)
}
let allFeatures = [].concat.apply([], getIndividualFeatures);
console.log(allFeatures)
编辑:如果您想让它们分开,请检查console.log(getIndividualFeatures)
之前allFeatures
是否已启动。
推荐阅读
- tally - Tally 实例运行模式
- linux - 一个线性终端命令,用于将目录中的所有文件重命名为其哈希值
- php - 未找到聊天机器人机器人工作室
- r - 如何在ggplot中用空格替换下划线?
- malloc - Windows 服务器上 IOCP 消息的性能 - 使用 malloc 或固定大小的缓冲区?
- javascript - 自动化函数 jquery 的问题
- syslog - Fluentd to Rsyslog:如何根据事件字段值将事件引导到 remore_syslog 中的不同程序?
- laravel - 无法安装 laravel-notification-channels/clickatell
- css - 你能帮我用“重复线性渐变”吗?我需要线条像照片上一样垂直内联
- hololens - MRTK 空间感知网格颜色为 NULL