Currently, I am working with the Vue programming language and have some demo code to showcase:
<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>
To determine whether list
has an entry with the name lava
and then retrieve the type of that entry, which is likely to be liquid
, how can this be done?