-1
let pokeArray = {
  pokemon: [
    {
      name: "Flabébé"  || "Flabebe",
      type: ["fairy"],
      imageData: "Not In Use",
      anchor: "Not In Use",
    },
]}


const pokeName = pokeArray.pokemon.map((x)=>x.name.toLowerCase())
let myPokemon = "Flabebe"
let inputMyPokemon = pokeName.indexOf(myPokemon.toLowerCase())

so this is the section of code im trying to get working "name: "Flabébé" || "Flabebe"," i want it to be easy for the user to type in the name without accents and get the same result

i could duplicate the array entry with the 2nd spelling, but i would rather use an or comparator in the array if possible

1 Answers1

-1

A better way to compare words, regardless of their accents and capitalization:

function areEquivalent(w1, w2) {
  return w1.localeCompare(w2, 'en', { sensitivity: 'base' }) === 0
}
areEquivalent("Flabébé", "flabebe") // true

Or as you are doing it:

let pokeArray = {
  pokemon: [
    {
      name: ["Flabébé", "Flabebe"], // <- Use an array
      type: ["fairy"],
      imageData: "Not In Use",
      anchor: "Not In Use",
    },
]}

const pokeName = pokeArray.pokemon[0].name.map((x)=>x.toLowerCase())
let myPokemon = "Flabebe"
let inputMyPokemon = pokeName.indexOf(myPokemon.toLowerCase())

Eric Fortis
  • 16,372
  • 6
  • 41
  • 62