迭代数组的对象

时间:2018-05-06 13:52:53

标签: javascript arrays function loops

我正在尝试编写一个以“弱点”作为输入的函数,并给出具有该弱点的所有口袋妖怪的名字。

考虑以下JSON:

访问https://raw.githubusercontent.com/Biuni/PokemonGO-Pokedex/master/pokedex.json

var pokemonWeakness = function(weaknessOfPokemon,allPokemon){
    for( x in allPokemon){
        if(weaknessOfPokemon==allPokemon[x].weaknesses){
            console.log('pokemon with this weaknesses are: '+allPokemon[x].name)
        }else{
            null
        }
    }
}

var weaknessOfPokemon = prompt('enter the weaknesses of pokemon')
pokemonWeakness(weaknessOfPokemon,pokemonData.pokemon)

此功能的问题是不返回任何数据。

4 个答案:

答案 0 :(得分:1)

通过检查他们的weaknesses数组Filter weaknessOfPokemon是否为

includes小精灵。使用Array.map()将名称提取到数组:



function findByPokemonWeakness(weaknessOfPokemon, pokemons){
  return pokemons.filter((o) => o.weaknesses.includes(weaknessOfPokemon))
    .map((o) => o.name);
}

fetch('https://raw.githubusercontent.com/Biuni/PokemonGO-Pokedex/master/pokedex.json')
  .then(r => r.json())
  .then(d => console.log(findByPokemonWeakness('Fire', d.pokemon)));




答案 1 :(得分:1)

由于您正在检查某个项目是否存在,因此您应该使用数组的includes()。所以你的if应该是:

if(allPokemon[x].weaknesses.includes(weaknessOfPokemon)){

您还应该return null;中有else

尝试以下方式:

var pokemonData = {
  "pokemon": [{
    "id": 1,
    "num": "001",
    "name": "Bulbasaur",
    "img": "http://www.serebii.net/pokemongo/pokemon/001.png",
    "type": [
      "Grass",
      "Poison"
    ],
    "height": "0.71 m",
    "weight": "6.9 kg",
    "candy": "Bulbasaur Candy",
    "candy_count": 25,
    "egg": "2 km",
    "spawn_chance": 0.69,
    "avg_spawns": 69,
    "spawn_time": "20:00",
    "multipliers": [1.58],
    "weaknesses": [
      "Fire",
      "Ice",
      "Flying",
      "Psychic"
    ],
    "next_evolution": [{
      "num": "002",
      "name": "Ivysaur"
    }, {
      "num": "003",
      "name": "Venusaur"
    }]
  }]
    
}

var pokemonWeakness = function(weaknessOfPokemon,allPokemon){
  for( x in allPokemon){
    if(allPokemon[x].weaknesses.includes(weaknessOfPokemon)){
      return 'pokemon with this weaknesses are: '+allPokemon[x].name;
    }else{
      return null
    }
  }
}

var weaknessOfPokemon = prompt('enter the weaknesses of pokemon')
console.log(pokemonWeakness(weaknessOfPokemon,pokemonData.pokemon))

答案 2 :(得分:0)

正如您所包含的json所示,weaknesses不是单个值,而是一个数组。我认为输入的是一个弱点,所以你应该做的,而不是检查是否相等,就是检查当前pokemen的weaknesses数组是否包含来自输​​入的弱点。

我认为这个提示足以帮助用户,无论如何,以下更新都应该这样做。

...
if(allPokemon[x].weaknesses.indexOf(weaknessOfPokemon) > -1){ 
...

答案 3 :(得分:0)

这里是一个简单的过滤器,每个解决方案只需将其包装在一个函数

obj.pokemon.filter(x=>x.weaknesses.includes("Fire")).forEach(x=>console.log(x.name))

注意:从对象中剪切一些记录(发布字符限制)

var obj = {
  "pokemon": [{
    "id": 78,
    "num": "078",
    "name": "Rapidash",
    "img": "http://www.serebii.net/pokemongo/pokemon/078.png",
    "type": [
      "Fire"
    ],
    "height": "1.70 m",
    "weight": "95.0 kg",
    "candy": "Ponyta Candy",
    "egg": "Not in Eggs",
    "spawn_chance": 0.011,
    "avg_spawns": 1.1,
    "spawn_time": "04:00",
    "multipliers": null,
    "weaknesses": [
      "Water",
      "Ground",
      "Rock"
    ],
    "prev_evolution": [{
      "num": "077",
      "name": "Ponyta"
    }]
  }, {
    "id": 79,
    "num": "079",
    "name": "Slowpoke",
    "img": "http://www.serebii.net/pokemongo/pokemon/079.png",
    "type": [
      "Water",
      "Psychic"
    ],
    "height": "1.19 m",
    "weight": "36.0 kg",
    "candy": "Slowpoke Candy",
    "candy_count": 50,
    "egg": "5 km",
    "spawn_chance": 1.05,
    "avg_spawns": 105,
    "spawn_time": "07:12",
    "multipliers": [2.21],
    "weaknesses": [
      "Electric",
      "Grass",
      "Bug",
      "Ghost",
      "Dark"
    ],
    "next_evolution": [{
      "num": "080",
      "name": "Slowbro"
    }]
  }, {
    "id": 110,
    "num": "110",
    "name": "Weezing",
    "img": "http://www.serebii.net/pokemongo/pokemon/110.png",
    "type": [
      "Poison"
    ],
    "height": "1.19 m",
    "weight": "9.5 kg",
    "candy": "Koffing Candy",
    "egg": "Not in Eggs",
    "spawn_chance": 0.016,
    "avg_spawns": 1.6,
    "spawn_time": "12:17",
    "multipliers": null,
    "weaknesses": [
      "Ground",
      "Psychic"
    ],
    "prev_evolution": [{
      "num": "109",
      "name": "Koffing"
    }]
  }, {
    "id": 111,
    "num": "111",
    "name": "Rhyhorn",
    "img": "http://www.serebii.net/pokemongo/pokemon/111.png",
    "type": [
      "Ground",
      "Rock"
    ],
    "height": "0.99 m",
    "weight": "115.0 kg",
    "candy": "Rhyhorn Candy",
    "candy_count": 50,
    "egg": "5 km",
    "spawn_chance": 0.63,
    "avg_spawns": 63,
    "spawn_time": "03:21",
    "multipliers": [1.91],
    "weaknesses": [
      "Water",
      "Grass",
      "Ice",
      "Fighting",
      "Ground",
      "Steel"
    ],
    "next_evolution": [{
      "num": "112",
      "name": "Rhydon"
    }]
  }, {
    "id": 112,
    "num": "112",
    "name": "Rhydon",
    "img": "http://www.serebii.net/pokemongo/pokemon/112.png",
    "type": [
      "Ground",
      "Rock"
    ],
    "height": "1.91 m",
    "weight": "120.0 kg",
    "candy": "Rhyhorn Candy",
    "egg": "Not in Eggs",
    "spawn_chance": 0.022,
    "avg_spawns": 2.2,
    "spawn_time": "05:50",
    "multipliers": null,
    "weaknesses": [
      "Water",
      "Grass",
      "Ice",
      "Fighting",
      "Ground",
      "Steel"
    ],
    "prev_evolution": [{
      "num": "111",
      "name": "Rhyhorn"
    }]
  }, {
    "id": 113,
    "num": "113",
    "name": "Chansey",
    "img": "http://www.serebii.net/pokemongo/pokemon/113.png",
    "type": [
      "Normal"
    ],
    "height": "1.09 m",
    "weight": "34.6 kg",
    "candy": "None",
    "egg": "10 km",
    "spawn_chance": 0.013,
    "avg_spawns": 1.3,
    "spawn_time": "04:46",
    "multipliers": null,
    "weaknesses": [
      "Fighting"
    ]
  }, {
    "id": 114,
    "num": "114",
    "name": "Tangela",
    "img": "http://www.serebii.net/pokemongo/pokemon/114.png",
    "type": [
      "Grass"
    ],
    "height": "0.99 m",
    "weight": "35.0 kg",
    "candy": "None",
    "egg": "5 km",
    "spawn_chance": 0.228,
    "avg_spawns": 22.8,
    "spawn_time": "23:13",
    "multipliers": null,
    "weaknesses": [
      "Fire",
      "Ice",
      "Poison",
      "Flying",
      "Bug"
    ]
  }, {
    "id": 115,
    "num": "115",
    "name": "Kangaskhan",
    "img": "http://www.serebii.net/pokemongo/pokemon/115.png",
    "type": [
      "Normal"
    ],
    "height": "2.21 m",
    "weight": "80.0 kg",
    "candy": "None",
    "egg": "5 km",
    "spawn_chance": 0.0086,
    "avg_spawns": 0.86,
    "spawn_time": "02:40",
    "multipliers": null,
    "weaknesses": [
      "Fighting"
    ]
  }, {
    "id": 116,
    "num": "116",
    "name": "Horsea",
    "img": "http://www.serebii.net/pokemongo/pokemon/116.png",
    "type": [
      "Water"
    ],
    "height": "0.41 m",
    "weight": "8.0 kg",
    "candy": "Horsea Candy",
    "candy_count": 50,
    "egg": "5 km",
    "spawn_chance": 1.13,
    "avg_spawns": 113,
    "spawn_time": "02:53",
    "multipliers": [2.23],
    "weaknesses": [
      "Electric",
      "Grass"
    ],
    "next_evolution": [{
      "num": "117",
      "name": "Seadra"
    }]
  }, {
    "id": 117,
    "num": "117",
    "name": "Seadra",
    "img": "http://www.serebii.net/pokemongo/pokemon/117.png",
    "type": [
      "Water"
    ],
    "height": "1.19 m",
    "weight": "25.0 kg",
    "candy": "Horsea Candy",
    "egg": "Not in Eggs",
    "spawn_chance": 0.034,
    "avg_spawns": 3.4,
    "spawn_time": "03:18",
    "multipliers": null,
    "weaknesses": [
      "Electric",
      "Grass"
    ],
    "prev_evolution": [{
      "num": "116",
      "name": "Horsea"
    }]
  }, {
    "id": 118,
    "num": "118",
    "name": "Goldeen",
    "img": "http://www.serebii.net/pokemongo/pokemon/118.png",
    "type": [
      "Water"
    ],
    "height": "0.61 m",
    "weight": "15.0 kg",
    "candy": "Goldeen Candy",
    "candy_count": 50,
    "egg": "5 km",
    "spawn_chance": 2.18,
    "avg_spawns": 218,
    "spawn_time": "03:14",
    "multipliers": [
      2.15,
      2.2
    ],
    "weaknesses": [
      "Electric",
      "Grass"
    ],
    "next_evolution": [{
      "num": "119",
      "name": "Seaking"
    }]
  }, {
    "id": 119,
    "num": "119",
    "name": "Seaking",
    "img": "http://www.serebii.net/pokemongo/pokemon/119.png",
    "type": [
      "Water"
    ],
    "height": "1.30 m",
    "weight": "39.0 kg",
    "candy": "Goldeen Candy",
    "egg": "Not in Eggs",
    "spawn_chance": 0.08,
    "avg_spawns": 8,
    "spawn_time": "05:21",
    "multipliers": null,
    "weaknesses": [
      "Electric",
      "Grass"
    ],
    "prev_evolution": [{
      "num": "118",
      "name": "Goldeen"
    }]
  }, {
    "id": 120,
    "num": "120",
    "name": "Staryu",
    "img": "http://www.serebii.net/pokemongo/pokemon/120.png",
    "type": [
      "Water"
    ],
    "height": "0.79 m",
    "weight": "34.5 kg",
    "candy": "Staryu Candy",
    "candy_count": 50,
    "egg": "5 km",
    "spawn_chance": 1.95,
    "avg_spawns": 195,
    "spawn_time": "22:59",
    "multipliers": [
      2.38,
      2.41
    ],
    "weaknesses": [
      "Electric",
      "Grass"
    ],
    "next_evolution": [{
      "num": "121",
      "name": "Starmie"
    }]
  }, {
    "id": 121,
    "num": "121",
    "name": "Starmie",
    "img": "http://www.serebii.net/pokemongo/pokemon/121.png",
    "type": [
      "Water",
      "Psychic"
    ],
    "height": "1.09 m",
    "weight": "80.0 kg",
    "candy": "Staryu Candy",
    "egg": "Not in Eggs",
    "spawn_chance": 0.034,
    "avg_spawns": 3.4,
    "spawn_time": "06:57",
    "multipliers": null,
    "weaknesses": [
      "Electric",
      "Grass",
      "Bug",
      "Ghost",
      "Dark"
    ],
    "prev_evolution": [{
      "num": "120",
      "name": "Staryu"
    }]
  }, {
    "id": 122,
    "num": "122",
    "name": "Mr. Mime",
    "img": "http://www.serebii.net/pokemongo/pokemon/122.png",
    "type": [
      "Psychic"
    ],
    "height": "1.30 m",
    "weight": "54.5 kg",
    "candy": "None",
    "egg": "10 km",
    "spawn_chance": 0.0031,
    "avg_spawns": 0.31,
    "spawn_time": "01:51",
    "multipliers": null,
    "weaknesses": [
      "Bug",
      "Ghost",
      "Dark"
    ]
  }, {
    "id": 123,
    "num": "123",
    "name": "Scyther",
    "img": "http://www.serebii.net/pokemongo/pokemon/123.png",
    "type": [
      "Bug",
      "Flying"
    ],
    "height": "1.50 m",
    "weight": "56.0 kg",
    "candy": "None",
    "egg": "10 km",
    "spawn_chance": 0.14,
    "avg_spawns": 14,
    "spawn_time": "05:43",
    "multipliers": null,
    "weaknesses": [
      "Fire",
      "Electric",
      "Ice",
      "Flying",
      "Rock"
    ]
  }, {
    "id": 124,
    "num": "124",
    "name": "Jynx",
    "img": "http://www.serebii.net/pokemongo/pokemon/124.png",
    "type": [
      "Ice",
      "Psychic"
    ],
    "height": "1.40 m",
    "weight": "40.6 kg",
    "candy": "None",
    "egg": "10 km",
    "spawn_chance": 0.35,
    "avg_spawns": 35,
    "spawn_time": "05:41",
    "multipliers": null,
    "weaknesses": [
      "Fire",
      "Bug",
      "Rock",
      "Ghost",
      "Dark",
      "Steel"
    ]
  }, {
    "id": 125,
    "num": "125",
    "name": "Electabuzz",
    "img": "http://www.serebii.net/pokemongo/pokemon/125.png",
    "type": [
      "Electric"
    ],
    "height": "1.09 m",
    "weight": "30.0 kg",
    "candy": "None",
    "egg": "10 km",
    "spawn_chance": 0.074,
    "avg_spawns": 7.4,
    "spawn_time": "04:28",
    "multipliers": null,
    "weaknesses": [
      "Ground"
    ]
  }, {
    "id": 126,
    "num": "126",
    "name": "Magmar",
    "img": "http://www.serebii.net/pokemongo/pokemon/126.png",
    "type": [
      "Fire"
    ],
    "height": "1.30 m",
    "weight": "44.5 kg",
    "candy": "None",
    "egg": "10 km",
    "spawn_chance": 0.10,
    "avg_spawns": 10,
    "spawn_time": "20:36",
    "multipliers": null,
    "weaknesses": [
      "Water",
      "Ground",
      "Rock"
    ]
  }, {
    "id": 127,
    "num": "127",
    "name": "Pinsir",
    "img": "http://www.serebii.net/pokemongo/pokemon/127.png",
    "type": [
      "Bug"
    ],
    "height": "1.50 m",
    "weight": "55.0 kg",
    "candy": "None",
    "egg": "10 km",
    "spawn_chance": 0.99,
    "avg_spawns": 99,
    "spawn_time": "03:25",
    "multipliers": null,
    "weaknesses": [
      "Fire",
      "Flying",
      "Rock"
    ]
  }, {
    "id": 128,
    "num": "128",
    "name": "Tauros",
    "img": "http://www.serebii.net/pokemongo/pokemon/128.png",
    "type": [
      "Normal"
    ],
    "height": "1.40 m",
    "weight": "88.4 kg",
    "candy": "None",
    "egg": "5 km",
    "spawn_chance": 0.12,
    "avg_spawns": 12,
    "spawn_time": "00:37",
    "multipliers": null,
    "weaknesses": [
      "Fighting"
    ]
  }, {
    "id": 129,
    "num": "129",
    "name": "Magikarp",
    "img": "http://www.serebii.net/pokemongo/pokemon/129.png",
    "type": [
      "Water"
    ],
    "height": "0.89 m",
    "weight": "10.0 kg",
    "candy": "Magikarp Candy",
    "candy_count": 400,
    "egg": "2 km",
    "spawn_chance": 4.78,
    "avg_spawns": 478,
    "spawn_time": "14:26",
    "multipliers": [
      10.1,
      11.8
    ],
    "weaknesses": [
      "Electric",
      "Grass"
    ],
    "next_evolution": [{
      "num": "130",
      "name": "Gyarados"
    }]
  }, {
    "id": 130,
    "num": "130",
    "name": "Gyarados",
    "img": "http://www.serebii.net/pokemongo/pokemon/130.png",
    "type": [
      "Water",
      "Flying"
    ],
    "height": "6.50 m",
    "weight": "235.0 kg",
    "candy": "Magikarp Candy",
    "egg": "Not in Eggs",
    "spawn_chance": 0.0032,
    "avg_spawns": 0.32,
    "spawn_time": "02:15",
    "multipliers": null,
    "weaknesses": [
      "Electric",
      "Rock"
    ],
    "prev_evolution": [{
      "num": "129",
      "name": "Magikarp"
    }]
  }, {
    "id": 131,
    "num": "131",
    "name": "Lapras",
    "img": "http://www.serebii.net/pokemongo/pokemon/131.png",
    "type": [
      "Water",
      "Ice"
    ],
    "height": "2.49 m",
    "weight": "220.0 kg",
    "candy": "None",
    "egg": "10 km",
    "spawn_chance": 0.006,
    "avg_spawns": 0.6,
    "spawn_time": "08:59",
    "multipliers": null,
    "weaknesses": [
      "Electric",
      "Grass",
      "Fighting",
      "Rock"
    ]
  }, {
    "id": 132,
    "num": "132",
    "name": "Ditto",
    "img": "http://www.serebii.net/pokemongo/pokemon/132.png",
    "type": [
      "Normal"
    ],
    "height": "0.30 m",
    "weight": "4.0 kg",
    "candy": "None",
    "egg": "Not in Eggs",
    "spawn_chance": 0,
    "avg_spawns": 0,
    "spawn_time": "N/A",
    "multipliers": null,
    "weaknesses": [
      "Fighting"
    ]
  }, {
    "id": 133,
    "num": "133",
    "name": "Eevee",
    "img": "http://www.serebii.net/pokemongo/pokemon/133.png",
    "type": [
      "Normal"
    ],
    "height": "0.30 m",
    "weight": "6.5 kg",
    "candy": "Eevee Candy",
    "candy_count": 25,
    "egg": "10 km",
    "spawn_chance": 2.75,
    "avg_spawns": 275,
    "spawn_time": "05:32",
    "multipliers": [
      2.02,
      2.64
    ],
    "weaknesses": [
      "Fighting"
    ],
    "next_evolution": [{
      "num": "134",
      "name": "Vaporeon"
    }, {
      "num": "135",
      "name": "Jolteon"
    }, {
      "num": "136",
      "name": "Flareon"
    }]
  }, {
    "id": 134,
    "num": "134",
    "name": "Vaporeon",
    "img": "http://www.serebii.net/pokemongo/pokemon/134.png",
    "type": [
      "Water"
    ],
    "height": "0.99 m",
    "weight": "29.0 kg",
    "candy": "Eevee Candy",
    "egg": "Not in Eggs",
    "spawn_chance": 0.014,
    "avg_spawns": 1.4,
    "spawn_time": "10:54",
    "multipliers": null,
    "weaknesses": [
      "Electric",
      "Grass"
    ],
    "prev_evolution": [{
      "num": "133",
      "name": "Eevee"
    }]
  }, {
    "id": 135,
    "num": "135",
    "name": "Jolteon",
    "img": "http://www.serebii.net/pokemongo/pokemon/135.png",
    "type": [
      "Electric"
    ],
    "height": "0.79 m",
    "weight": "24.5 kg",
    "candy": "None",
    "egg": "Not in Eggs",
    "spawn_chance": 0.012,
    "avg_spawns": 1.2,
    "spawn_time": "02:30",
    "multipliers": null,
    "weaknesses": [
      "Ground"
    ],
    "prev_evolution": [{
      "num": "133",
      "name": "Eevee"
    }]
  }, {
    "id": 136,
    "num": "136",
    "name": "Flareon",
    "img": "http://www.serebii.net/pokemongo/pokemon/136.png",
    "type": [
      "Fire"
    ],
    "height": "0.89 m",
    "weight": "25.0 kg",
    "candy": "Eevee Candy",
    "egg": "Not in Eggs",
    "spawn_chance": 0.017,
    "avg_spawns": 1.7,
    "spawn_time": "07:02",
    "multipliers": null,
    "weaknesses": [
      "Water",
      "Ground",
      "Rock"
    ],
    "prev_evolution": [{
      "num": "133",
      "name": "Eevee"
    }]
  }, {
    "id": 137,
    "num": "137",
    "name": "Porygon",
    "img": "http://www.serebii.net/pokemongo/pokemon/137.png",
    "type": [
      "Normal"
    ],
    "height": "0.79 m",
    "weight": "36.5 kg",
    "candy": "None",
    "egg": "5 km",
    "spawn_chance": 0.012,
    "avg_spawns": 1.2,
    "spawn_time": "02:49",
    "multipliers": null,
    "weaknesses": [
      "Fighting"
    ]
  }, {
    "id": 138,
    "num": "138",
    "name": "Omanyte",
    "img": "http://www.serebii.net/pokemongo/pokemon/138.png",
    "type": [
      "Rock",
      "Water"
    ],
    "height": "0.41 m",
    "weight": "7.5 kg",
    "candy": "Omanyte Candy",
    "candy_count": 50,
    "egg": "10 km",
    "spawn_chance": 0.14,
    "avg_spawns": 14,
    "spawn_time": "10:23",
    "multipliers": [2.12],
    "weaknesses": [
      "Electric",
      "Grass",
      "Fighting",
      "Ground"
    ],
    "next_evolution": [{
      "num": "139",
      "name": "Omastar"
    }]
  }, {
    "id": 139,
    "num": "139",
    "name": "Omastar",
    "img": "http://www.serebii.net/pokemongo/pokemon/139.png",
    "type": [
      "Rock",
      "Water"
    ],
    "height": "0.99 m",
    "weight": "35.0 kg",
    "candy": "None",
    "egg": "Omanyte Candy",
    "spawn_chance": 0.0061,
    "avg_spawns": 0.61,
    "spawn_time": "05:04",
    "multipliers": null,
    "weaknesses": [
      "Electric",
      "Grass",
      "Fighting",
      "Ground"
    ],
    "prev_evolution": [{
      "num": "138",
      "name": "Omanyte"
    }]
  }, {
    "id": 140,
    "num": "140",
    "name": "Kabuto",
    "img": "http://www.serebii.net/pokemongo/pokemon/140.png",
    "type": [
      "Rock",
      "Water"
    ],
    "height": "0.51 m",
    "weight": "11.5 kg",
    "candy": "Kabuto Candy",
    "candy_count": 50,
    "egg": "10 km",
    "spawn_chance": 0.10,
    "avg_spawns": 10,
    "spawn_time": "00:05",
    "multipliers": [
      1.97,
      2.37
    ],
    "weaknesses": [
      "Electric",
      "Grass",
      "Fighting",
      "Ground"
    ],
    "next_evolution": [{
      "num": "141",
      "name": "Kabutops"
    }]
  }, {
    "id": 141,
    "num": "141",
    "name": "Kabutops",
    "img": "http://www.serebii.net/pokemongo/pokemon/141.png",
    "type": [
      "Rock",
      "Water"
    ],
    "height": "1.30 m",
    "weight": "40.5 kg",
    "candy": "Kabuto Candy",
    "egg": "Not in Eggs",
    "spawn_chance": 0.0032,
    "avg_spawns": 0.32,
    "spawn_time": "23:40",
    "multipliers": null,
    "weaknesses": [
      "Electric",
      "Grass",
      "Fighting",
      "Ground"
    ],
    "prev_evolution": [{
      "num": "140",
      "name": "Kabuto"
    }]
  }, {
    "id": 142,
    "num": "142",
    "name": "Aerodactyl",
    "img": "http://www.serebii.net/pokemongo/pokemon/142.png",
    "type": [
      "Rock",
      "Flying"
    ],
    "height": "1.80 m",
    "weight": "59.0 kg",
    "candy": "None",
    "egg": "10 km",
    "spawn_chance": 0.018,
    "avg_spawns": 1.8,
    "spawn_time": "23:40",
    "multipliers": null,
    "weaknesses": [
      "Water",
      "Electric",
      "Ice",
      "Rock",
      "Steel"
    ]
  }, {
    "id": 143,
    "num": "143",
    "name": "Snorlax",
    "img": "http://www.serebii.net/pokemongo/pokemon/143.png",
    "type": [
      "Normal"
    ],
    "height": "2.11 m",
    "weight": "460.0 kg",
    "candy": "None",
    "egg": "10 km",
    "spawn_chance": 0.016,
    "avg_spawns": 1.6,
    "spawn_time": "23:40",
    "multipliers": null,
    "weaknesses": [
      "Fighting"
    ]
  }, {
    "id": 144,
    "num": "144",
    "name": "Articuno",
    "img": "http://www.serebii.net/pokemongo/pokemon/144.png",
    "type": [
      "Ice",
      "Flying"
    ],
    "height": "1.70 m",
    "weight": "55.4 kg",
    "candy": "None",
    "egg": "Not in Eggs",
    "spawn_chance": 0,
    "avg_spawns": 0,
    "spawn_time": "N/A",
    "multipliers": null,
    "weaknesses": [
      "Fire",
      "Electric",
      "Rock",
      "Steel"
    ]
  }, {
    "id": 145,
    "num": "145",
    "name": "Zapdos",
    "img": "http://www.serebii.net/pokemongo/pokemon/145.png",
    "type": [
      "Electric",
      "Flying"
    ],
    "height": "1.60 m",
    "weight": "52.6 kg",
    "candy": "None",
    "egg": "Not in Eggs",
    "spawn_chance": 0,
    "avg_spawns": 0,
    "spawn_time": "N/A",
    "multipliers": null,
    "weaknesses": [
      "Ice",
      "Rock"
    ]
  }, {
    "id": 146,
    "num": "146",
    "name": "Moltres",
    "img": "http://www.serebii.net/pokemongo/pokemon/146.png",
    "type": [
      "Fire",
      "Flying"
    ],
    "height": "2.01 m",
    "weight": "60.0 kg",
    "candy": "None",
    "egg": "Not in Eggs",
    "spawn_chance": 0,
    "avg_spawns": 0,
    "spawn_time": "N/A",
    "multipliers": null,
    "weaknesses": [
      "Water",
      "Electric",
      "Rock"
    ]
  }, {
    "id": 147,
    "num": "147",
    "name": "Dratini",
    "img": "http://www.serebii.net/pokemongo/pokemon/147.png",
    "type": [
      "Dragon"
    ],
    "height": "1.80 m",
    "weight": "3.3 kg",
    "candy": "Dratini Candy",
    "candy_count": 25,
    "egg": "10 km",
    "spawn_chance": 0.30,
    "avg_spawns": 30,
    "spawn_time": "06:41",
    "multipliers": [
      1.83,
      1.84
    ],
    "weaknesses": [
      "Ice",
      "Dragon",
      "Fairy"
    ],
    "next_evolution": [{
      "num": "148",
      "name": "Dragonair"
    }, {
      "num": "149",
      "name": "Dragonite"
    }]
  }, {
    "id": 148,
    "num": "148",
    "name": "Dragonair",
    "img": "http://www.serebii.net/pokemongo/pokemon/148.png",
    "type": [
      "Dragon"
    ],
    "height": "3.99 m",
    "weight": "16.5 kg",
    "candy": "Dratini Candy",
    "candy_count": 100,
    "egg": "Not in Eggs",
    "spawn_chance": 0.02,
    "avg_spawns": 2,
    "spawn_time": "11:57",
    "multipliers": [2.05],
    "weaknesses": [
      "Ice",
      "Dragon",
      "Fairy"
    ],
    "prev_evolution": [{
      "num": "147",
      "name": "Dratini"
    }],
    "next_evolution": [{
      "num": "149",
      "name": "Dragonite"
    }]
  }, {
    "id": 149,
    "num": "149",
    "name": "Dragonite",
    "img": "http://www.serebii.net/pokemongo/pokemon/149.png",
    "type": [
      "Dragon",
      "Flying"
    ],
    "height": "2.21 m",
    "weight": "210.0 kg",
    "candy": "Dratini Candy",
    "egg": "Not in Eggs",
    "spawn_chance": 0.0011,
    "avg_spawns": 0.11,
    "spawn_time": "23:38",
    "multipliers": null,
    "weaknesses": [
      "Ice",
      "Rock",
      "Dragon",
      "Fairy"
    ],
    "prev_evolution": [{
      "num": "147",
      "name": "Dratini"
    }, {
      "num": "148",
      "name": "Dragonair"
    }]
  }, {
    "id": 150,
    "num": "150",
    "name": "Mewtwo",
    "img": "http://www.serebii.net/pokemongo/pokemon/150.png",
    "type": [
      "Psychic"
    ],
    "height": "2.01 m",
    "weight": "122.0 kg",
    "candy": "None",
    "egg": "Not in Eggs",
    "spawn_chance": 0,
    "avg_spawns": 0,
    "spawn_time": "N/A",
    "multipliers": null,
    "weaknesses": [
      "Bug",
      "Ghost",
      "Dark"
    ]
  }, {
    "id": 151,
    "num": "151",
    "name": "Mew",
    "img": "http://www.serebii.net/pokemongo/pokemon/151.png",
    "type": [
      "Psychic"
    ],
    "height": "0.41 m",
    "weight": "4.0 kg",
    "candy": "None",
    "egg": "Not in Eggs",
    "spawn_chance": 0,
    "avg_spawns": 0,
    "spawn_time": "N/A",
    "multipliers": null,
    "weaknesses": [
      "Bug",
      "Ghost",
      "Dark"
    ]
  }]
};

obj.pokemon.filter(x=>x.weaknesses.includes("Fire")).forEach(x=>console.log(x.name))