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

120
Vistas
Express Backend Application, destructure an array of objects and return new array of objects

I'm working with an api in a mern app, on the backend I would like to destructor the array of objects, run a function on an item each each of the arrays and return a new array of objects or add the new value to the array. Here is my controller

const getObjects = async (req, res) => {
  const { bucketKey } = req.params
  const bucket = await new ForgeSDK.ObjectsApi().getObjects(
    bucketKey,
    req.params.objectName,
    req.oauth_client,
    req.oauth_token
  )
  const bucketObjects = bucket.body.items
  // const encodedUrn = urnify(objectKey)
  res.status(StatusCodes.OK).json({
    bucketObjects,
    totalObjects: bucketObjects.length,
    numOfPages: 1,
  })
}

So each item in the array of bucketObjects has an objectKey, I would like to take the objectKey convert it to a Base64-encoded string and create a new array of objects

Here is the response I am returning in postman

    "bucketObjects": [
        {
            "bucketKey": "dashboard",
            "objectKey": "BRISMETRO-BRM-ADLSTSO00-3DM-000020.ifc",
            "objectId": "urn:adsk.objects:os.object:dashboard/BRISMETRO-BRM-ADLSTSO00-3DM-000020.ifc",
            "sha1": "4ed04b922c8863ac8323226da2a5f974730d13f0",
            "size": 937888,
            "location": "https://developer.api.autodesk.com/oss/v2/buckets/dashboard/objects/BRISMETRO-BRM-ADLSTSO00-3DM-000020.ifc"
        },
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You can simply use map function to return a new array.

const newArray = bucketObjects.map((object) => {
  return {
    ...object,
    objectKey: conversionToBase64(object.objectKey)
  }
})
about 4 years ago · Juan Pablo Isaza Denunciar

0

Transform each element of your array with a simple forEach iterator before sending the response.

const getObjects = async (req, res) => {
  ...
  const bucketObjects = bucket.body.items;
  bucketObjects.forEach(obj => obj.key = new Buffer(obj.objectKey).toString('base64'));
  res.status(StatusCodes.OK).json({
    bucketObjects,
    ...
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