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

148
Vistas
Vuejs template list array values which its keys starts with special string

I hava a vuejs template and it shows values of a nested array. example array is:

myArray : [
{
  name: "abc",
  
},
{
  name123: "bcf"
},
{
  name12456: "fdf"
}
]
<template> 
<div>
{{ node.name }}
</div>
</template>

When I call objects of this array I can show "abc" value with {{ node.name }} but I want to show the keys starts with "name" string. So, with this way I can list all values.

Note: I just want to show keys with starts "name". There may be different keys in different arrays.

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

0

You can try with computed property and Object.keys :

new Vue({
  el: '#demo',
  data() {
    return {
      myArray: [
        {name: "abc"}, 
        {nn00: 'rrr'},
        {name123: "bcf", ar: [{name9: 'nested1'}]}, 
        {name12456: "fdf"}, 
        {no78: "eee", ar: [{name8: 'nested2'}]}],
      res: []
    }
  },
  methods: {
    getValues(arr) {
      arr.forEach(a => {
        let val = Object.keys(a).filter(k => {
          if (typeof a[k] === 'object') this.getValues(a[k])
          return k.startsWith('name')
        })
        this.res.push(a[val])
      })
    }
  },
  mounted() {
    this.getValues(this.myArray)
  }
})

Vue.config.productionTip = false
Vue.config.devtools = false
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="demo">
  <div v-for="(node, i) in res" :key="i">
  {{ node }}
  </div>
</div>

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