Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

250
Vistas
How can I convert string into an imported alias in React?

I have got an image folder that contains images of playing cards and I imported them as follow:

import D2 from "../image/D2.png";
import H2 from "../image/H2.png";
import S2 from "../image/S2.png"; 

and all the way until I reach SA (Spade Ace)

I also have key value pair dictionary such as:

  1: "C2",
  2: "D2",
  3: "H2",
  4: "S2",... 

I need this dictionary to both calculate the rank of the card and to generate image.

atm I can retrieve the value by evaluating the last char of the string and convert it into int (in case of K,Q etc I have a switch case for them)

My issue is I have trouble to convert the string into the alias that I imported. I tried doing eval(4) but it didn't work.

if I modified the dictionary into

  1: C2,
  2: D2,
  3: H2,
  4: S2,...

I can easily use this as the src of my images, but I can no longer use the card-code to obtain the value of the card.

Could you please suggest a solution or a better approach for this problem.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

If I follow the question properly can't you just create the dictionary in this manner? If you intend to use card codes to obtain the value / image then you could build your dictionary like so:

dict = {
  C2: { image: C2, value: 1 },
  D2: { image: D2, value: 2 },
  ...
}

c2Image = dict['C2'].image;
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda