javascript - 获取引用错误: appearance is not defined

标签 javascript html api

我正在尝试访问 super 英雄 api,但对于某些数据,它一直显示数据未定义。

 var html = "";
$.each(data.results,function(i,results){
html += "<li> first appearance: " + results.biography.first-appearance +"</li>";
// it is not showing anything with a "-" in but the rest are working fine 

 })
 $("#Results").html(html);

最佳答案

就像需要引用带有连字符的对象键一样,当您访问该键时,您需要使用带引号的方括号表示法:

const a = [{ biography: 'a', 'first-appearance': 'b' }];
    
console.log(a[0]['first-appearance'])

关于javascript - 获取引用错误: appearance is not defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59112057/

相关文章:

javascript - VueJs 如何使用限制器和范围进行分页..?

html - 当从 phpmailer 打印电子邮件时,gmail 不会应用 css

html - 向水平条形图添加标签

api - Mailchimp API (v1.3) : addresses added with listSubscribe() don't appear in dashboard

c - 如何编写 Windows 应用程序?

javascript - Web Audio API 中 AudioWorkerNode 的状态

javascript - rivets.js:使用 init View 中的数据预填充模型

php - php 中的 json 解码问题

html - 在页面上进行打印预览时,div 背景颜色不会出现

Android SIP API : Shows supported, 但错误 'not supported'