Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

147
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!