javascript - 如何过滤90分以上的分数?

标签 javascript arrays

const shows = [
  {
    title: `legion`,
    season: 1,
    score: 94,
  }, {
    title: `sneaky pete`,
    season: 1,
    score: 100,
  }, {
    title: `santa clarita diet`,
    season: 1,
    score: 71,
  }, {
    title: `riverdale`,
    season: 1,
    score: 87,
  }, {
    title: `the young pope`,
    season: 1,
    score: 74,
  }, {
    title: `a series of unfortunate events`,
    season: 1,
    score: 94,
  }, {
    title: `taboo`,
    season: 1,
    score: 78,
  }, {
    title: `colony`,
    season: 2,
    score: 100,
  }, {
    title: `24: legacy`,
    season: 1,
    score: 57,
  }, {
    title: `speechless`,
    season: 1,
    score: 98,
  }, {
    title: `scherlock`,
    season: 4,
    score: 65,
  }, {
    title: `stranger things`,
    season: 1,
    score: 95,
  }, {
    title: `this is us`,
    season: 1,
    score: 89,
  }, {
    title: `timeless`,
    season: 1,
    score: 84,
  }, {
    title: `the oa`,
    season: 1,
    score: 73,
  },
];

const wrapWithTag = (content, tagname) => `<${tagname}>${content}</${tagname}>`;

const topScoreFilter = show => { 90, 95, 94, 100 };

shows.filter(topScoreFilter);

document.write(`<ol>`);
shows.forEach(show => document.write(wrapWithTag(show.title + ` ` + `(` + show.score + `%` + `)`, `li`)));
document.write(`</ol>`);

如何才能让标题90分以上的分数显示,90分以下的分数不显示?

最佳答案

您可以使用过滤器:

var aboveNinety = shows.filter(show=>show.score > 90);

关于javascript - 如何过滤90分以上的分数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42476163/

相关文章:

java - 查找缺失数字时的数组异常

java - 该系统找不到指定的文件?

javascript - 有机会从选项中生成随机值

javascript - Select2 关闭事件触发后聚焦输入

javascript - Jquery点击隐藏元素

javascript - 通过将 php 数组传递给 javascript 函数来填充下拉列表 onload

javascript - Javascript 中的关联数组 键是数字,但作为字符串访问(关联)

Javascript按数组对对象数组进行排序

javascript - 如何让异步/等待等待我的嵌套数组填充

javascript - 有什么方法可以在 React Native 应用程序中使用 p5.js 吗?