I have searched on the website for solutions, but I have had no luck. I need to make this data global. My code is present below:
function val() {
var plans = @json($plans);
var id = document.getElementById("plan_id").value;
plans.forEach(function(element) {
if (id == element.id) {
var i = element.amount;
return i;
}
});
}
var obj = val()
console.log(obj)
After I log that, it wont give any values but if I log inside the foreach, I will get the amount. Pls how can I access data inside foreach