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

98
Vistas
¿Cómo verificar si el objeto con algunos datos está en una matriz en javascript?

El lenguaje de programación que estoy usando actualmente es Vue . Tengo un código de demostración aquí:

 <template> <button @click="checkInList">Check</button> </template> <script> import { ref } from "@vue/reactivity"; export default { name: "App", setup() { const firstInput = ref(""); const secondInput = ref(""); const list = ref([ { name: "lava", kind: "liquid" }, { name: "air", kind: "gas" }, { name: "water", kind: "liquid" }, { name: "earth", kind: "object" }, ]); const checkInList = () => { if (list.value.includes({ name: "lava", kind: "liquid" })) { console.log("array includes lava"); // here I want to return the kind of that element, which will be liquid } }; return { firstInput, secondInput, checkInList, }; }, }; </script>

Entonces, ¿cómo puedo verificar si la list contiene el objeto con el nombre lava y luego devolver el tipo de ese objeto, que será liquid ?

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

0

Puede usar el campo de búsqueda y devolución que desee:

 const { ref } = Vue const app = Vue.createApp({ setup() { const firstInput = ref(""); const secondInput = ref(""); const list = ref([ { name: "lava", kind: "liquid" }, { name: "air", kind: "gas" }, { name: "water", kind: "liquid" }, { name: "earth", kind: "object" }, ]); const checkInList = () => { return list.value.find(l => l.name.includes(firstInput.value)).kind }; return { firstInput, secondInput, checkInList, }; }, }) app.mount('#demo')
 So how can I check if list contains the object with name lava and then return the kind of that object, which will be liquid?
 <script src="https://unpkg.com/vue@3/dist/vue.global.prod.js"></script> <div id="demo"> <button @click="checkInList">Check</button> <input v-model="firstInput" /> <p>{{ checkInList() }}</p> </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