how can i change my javascript variable to a razor variable in mvc.
let data = JSON.parse(this.responseText).data.Table;
this is my javascript variable.
what is razor variable?
i want to use this variable in foreach loop in mvc
if the data is an Object, then you can’t use forEach
. If data is an array, then you can use it. What is type
data?
If it is an Object, than you can use Object.keys
to loop over the keys.
let obj = {a: 1, b: 2};
Object.keys(obj).forEach(e => console.log(obj[e])) // 1, 2