Is there a way to save the value of naziv.value
in var naziv
within the find method
without declaring another variable?
var naziv = obj.find(c => c.name === "naziv");
console.log(naziv)
The current output is test
when using console.log(naziv.value)
, but I would prefer just using console.log(naziv)
.
var obj = [{
name: "naziv",
value: "test"
},
{
name: "zzz",
value: "xxx"
}
]
var naziv = obj.find(c => c.name === "naziv");
console.log(naziv.value)
EDIT: And also, if the name is the same, how can we create an array of values? For example:
var obj = [{
name: "naziv",
value: "test"
},
{
name: "zzz",
value: "xxx"
},
{
name: "Telefon[]",
value: "tel1"
}, {
name: "Telefon[]",
value: "tel2"
}
]
var naziv = obj.find(c => c.name === "Telefon[]");
console.log(naziv.value)
The expected result is: [tel1,tel2]