如何筛选高于90的分数?

时间:2017-02-27 00:50:47

标签: 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的分数不会显示?

1 个答案:

答案 0 :(得分:4)

您可以使用filter

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