如何在javascript表格中垂直显示数组
我希望有人能帮我找到一种垂直打印数组的方法。请注意我的数组长度不相等如何在javascript表格中垂直显示数组,javascript,jquery,html,Javascript,Jquery,Html,我希望有人能帮我找到一种垂直打印数组的方法。请注意我的数组长度不相等 [ ["birthdate", "birthmonth", "contact_id", "company_id", "contact_type_id", "type_name", "vendor_type_id", "is_active", "first_name", "last_name", "email_address", "phone_number", "mobile_number", "fax_number",
[
["birthdate", "birthmonth", "contact_id", "company_id", "contact_type_id", "type_name", "vendor_type_id", "is_active", "first_name", "last_name", "email_address", "phone_number", "mobile_number", "fax_number", "address", "state_id", "state_name", "zip_code", "labels", "profile_logo", "website_url", "employees", "parent_id"],
["3", "2", "244", "3", "1", "Customers", null, "1", "sorthia", "daksh choratiya", "hellodaksh@gmail.com", "8787877887", "7878787887", "7.87879E+11", "sdfkjhfkd", null, null, "45454", ",undefined,", "https://s3.us-west-2.amazonaws.com/home-inspection%2FContactsCSV-EXCEL-Files/1519826594241_download.png"],
[null, null, "515", "3", "1", "Customers", null, "1", "prashant", "gadhiya bhai", "pg@gmail.com", "1231321321", "1321321313", "1321321231", "13213213", "1", "Alabama", "12345", ",undefined,"],
["11", "11", "529", "3", "1", "Customers", null, "1", "Hardik bhai bhai", "Patel bhai", "hardik121@gmail.com", "98765432100", "65498732100", "9.87978E+11", "Addrreess surat", "6", "Colorado", "987640", ",undefined,"]
]
我需要以下面的格式显示数据如何以垂直方式显示此数组
我需要如下表所示的输出我如何才能做到这一点
|birthdate | 3 | null |
|birthmonth | 2 | null |
|contact_id | 244 | 515 |
|company_id | 3 | 3 |
|contact_type_id | 1 | 1 |
你可以试试下面的 假设
var-arr=[
[“生日”、“生日”、“联系人id”、“公司id”、“联系人类型id”、“类型名称”、“供应商类型id”、“是否有效”、“名”、“姓”、“电子邮件地址”、“电话号码”、“手机号码”、“传真号码”、“地址”、“州id”、“州名”、“邮政编码”、“标签”、“个人资料标识”、“网站url”、“员工”、“家长id”],
[“3”,“2”,“244”,“3”,“1”,“客户”,空,“1”,“sorthia”,“daksh choratiya”hellodaksh@gmail.com“,”87877887“,”787887“,”7.87879E+11“,”sdfkjhfkd“,”空,空,“45454“,”未定义“,”https://s3.us-west-2.amazonaws.com/home-inspection%2FContactsCSV-EXCEL文件/1519826594241_download.png“],
[null,null,“515”,“3”,“1”,“客户”,null,“1”,“prashant”,“gadhiya bhai”pg@gmail.com“,“1231321”,“1321313”,“1321231”,“13213”,“1”,“阿拉巴马州”,“12345”,“未定义,”,
[“11”,“11”,“529”,“3”,“1”,“客户”,空,“1”,“Hardik bhai bhai”,“Patel bhai”hardik121@gmail.com“,“98765432100”,“65498732100”,“9.87978E+11”,“Addrress surat”,“6”,“Colorado”,“987640”,“未定义,”]
];
var result=arr[0]。映射(函数(项、索引){
var-temp=[];
对于(变量i=0;i 控制台日志(结果)代码>对于不同长度的数组,您只需进行if
检查即可
var arr = [
["birthdate", "birthmonth", "contact_id", "company_id", "contact_type_id", "type_name", "vendor_type_id", "is_active", "first_name", "last_name", "email_address", "phone_number", "mobile_number", "fax_number", "address", "state_id", "state_name", "zip_code", "labels", "profile_logo", "website_url", "employees", "parent_id"],
["3", "2", "244", "3", "1", "Customers", null, "1", "sorthia", "daksh choratiya", "hellodaksh@gmail.com", "8787877887", "7878787887", "7.87879E+11", "sdfkjhfkd", null, null, "45454", ",undefined,", "https://s3.us-west-2.amazonaws.com/home-inspection%2FContactsCSV-EXCEL-Files/1519826594241_download.png"],
[null, null, "515", "3", "1", "Customers", null, "1", "prashant", "gadhiya bhai", "pg@gmail.com", "1231321321", "1321321313", "1321321231", "13213213", "1", "Alabama", "12345", ",undefined,"],
["11", "11", "529", "3", "1", "Customers", null, "1", "Hardik bhai bhai", "Patel bhai", "hardik121@gmail.com", "98765432100", "65498732100", "9.87978E+11", "Addrreess surat", "6", "Colorado", "987640", ",undefined,"]
];
html = "<table>";
for (var i = 0; i < arr[0].length; i++) {
html += "<tr>";
for (var j = 0; j < arr.length; j++) {
var val = arr[j][i];
if (val == undefined || val == null) val = "-";
html += "<td>" + val + "</td>";
}
html += "</tr>";
}
html += "</table>";
$("body").append(html);
var-arr=[
[“生日”、“生日”、“联系人id”、“公司id”、“联系人类型id”、“类型名称”、“供应商类型id”、“是否有效”、“名”、“姓”、“电子邮件地址”、“电话号码”、“手机号码”、“传真号码”、“地址”、“州id”、“州名”、“邮政编码”、“标签”、“个人资料标识”、“网站url”、“员工”、“家长id”],
[“3”,“2”,“244”,“3”,“1”,“客户”,空,“1”,“sorthia”,“daksh choratiya”hellodaksh@gmail.com“,”87877887“,”787887“,”7.87879E+11“,”sdfkjhfkd“,”空,空,“45454“,”未定义“,”https://s3.us-west-2.amazonaws.com/home-inspection%2FContactsCSV-EXCEL文件/1519826594241_download.png“],
[null,null,“515”,“3”,“1”,“客户”,null,“1”,“prashant”,“gadhiya bhai”pg@gmail.com“,“1231321”,“1321313”,“1321231”,“13213”,“1”,“阿拉巴马州”,“12345”,“未定义,”,
[“11”,“11”,“529”,“3”,“1”,“客户”,空,“1”,“Hardik bhai bhai”,“Patel bhai”hardik121@gmail.com“,“98765432100”,“65498732100”,“9.87978E+11”,“Addrress surat”,“6”,“Colorado”,“987640”,“未定义,”]
];
html=“”;
对于(var i=0;i
var-temp=[
[“生日”、“生日”、“联系人id”、“公司id”、“联系人类型id”、“类型名称”、“供应商类型id”、“是否有效”、“名”、“姓”、“电子邮件地址”、“电话号码”、“手机号码”、“传真号码”、“地址”、“州id”、“州名”、“邮政编码”、“标签”、“个人资料标识”、“网站url”、“员工”、“家长id”],
[“3”,“2”,“244”,“3”,“1”,“客户”,空,“1”,“sorthia”,“daksh choratiya”hellodaksh@gmail.com“,”87877887“,”787887“,”7.87879E+11“,”sdfkjhfkd“,”空,空,“45454“,”未定义“,”https://s3.us-west-2.amazonaws.com/home-inspection%2FContactsCSV-EXCEL文件/1519826594241_download.png“],
[null,null,“515”,“3”,“1”,“客户”,null,“1”,“prashant”,“gadhiya bhai”pg@gmail.com“,“1231321”,“1321313”,“1321231”,“13213”,“1”,“阿拉巴马州”,“12345”,“未定义,”,
[“11”,“11”,“529”,“3”,“1”,“客户”,空,“1”,“Hardik bhai bhai”,“Patel bhai”hardik121@gmail.com“,“98765432100”,“65498732100”,“9.87978E+11”,“Addrress surat”,“6”,“Colorado”,“987640”,“未定义,”]
];
var body=document.getElementsByTagName('body')[0];
var tbl=document.createElement('table');
tbl.style.width='50%';
tbl.setAttribute('border','1');
var tbdy=document.createElement('tbody');
对于(变量i=0;i body.appendChild(tbl)
您可以通过编写一些代码来实现这一点。代码中没有VUEJ。我现在已经删除了标记:)@PrAtikLochawala-是的,但您需要自定义上述代码-完全取决于您想要的输出