This works, but question is can I save the naziv.value in var naziv in one go, inside this find method so I don't have to declare another variable?
var naziv = obj.find(c => c.name === "naziv");
console.log(naziv.value)
Current output is as it should be test by console.log(naziv.value), I would like to be just 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 to make an array or values if name is the same, 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)
Should be: [tel1,tel2]
nameto be unique. Is there a chance it won't be/test for it not being?var naziv=obj.find(c => c.name === "naziv").value;const output = []; for(let o of obj) if(o.name === "naziv") output.push(o.value)var values=obj.filter(item=>item.name=="Telefon[]").map(item=>item.value)