Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Calculadora

0

75
Vistas
Can you pass an object key as a param? - Svelte/JS

I'm using Svelte and my component wants to take in an array of objects and a specific key. However it doesn't want to read the key when it is a variable. This is what I've tried so far.

  export let data = [];
  export let key;
  function cleanUp(data, key) {
    for (let i = 0; i < data.length; i++) {
      let d = data[i].key;
      newArray.push(d);
    }
  }

Is there anyway to make this work?

7 months ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

If the key variable contains a string, you can access an object's property with that name with object[key].

In your example:

let d = data[i][key];
7 months ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos