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

261
Vistas
How to convert a specific element in an array to number?

I want to convert the fileID that is in the current array from string to number, e.g: fileID: "1" to fileID: 1.

How to target the specific item (fileID) so that I can convert it to a number and map the current array into a new array?

Current array:

[
    {
      fileID: "1",
      fileName: "Cardio Care Awareness Month",
      createdByID: "100101"
    },
    {
      fileID: "2",
      fileName: "MEMO COMPULSORY TO",
      createdByID: "100101"
    },
    {
      fileID: "3",
      fileName: "MEMO 2021 Covid19 Vaccination Leave",
      createdByID: "200201"
    },
    {
      fileID: "4",
      fileName: "Human Cell",
      createdByID: "200201"
    }
]

New converted array:

[
    {
      fileID: 1,
      fileName: "Cardio Care Awareness Month",
      createdByID: "100101"
    },
    {
      fileID: 2,
      fileName: "MEMO COMPULSORY TO",
      createdByID: "100101"
    },
    {
      fileID: 3,
      fileName: "MEMO 2021 Covid19 Vaccination Leave",
      createdByID: "200201"
    },
    {
      fileID: 4,
      fileName: "Human Cell",
      createdByID: "200201"
    }
]

enter image description here

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

0

Here is a function that should convert the array into the format you want.

const convertArray = array => array.map(({fileID, ...item}) => ({fileID: Number(fileID), ...item}))
about 4 years ago · Juan Pablo Isaza Denunciar

0

You can create a custom function and re-use it in your application.

Example :

const parseData = (data, key) => {
    return data.map(item => {
        return {
         ...item,
         [key] : Number(item[key])
        }
    })
}

parseData(data, 'fileID')

0: {fileID: 1, fileName: 'Cardio Care Awareness Month', createdByID: '100101'}
1: {fileID: 2, fileName: 'MEMO COMPULSORY TO', createdByID: '100101'}
2: {fileID: 3, fileName: 'MEMO 2021 Covid19 Vaccination Leave', createdByID: '200201'}
3: {fileID: 4, fileName: 'Human Cell', createdByID: '200201'}
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