如何從定義字符串的對象獲取數據?從定義的字符串獲取對象元素
情況:
var data = [
{name:"Sharma",country:"India"},
{name:"Udin",country:"Indonesia"},
{name:"John Carter",country:"Mars"}
];
getData(data,"country");
function getData(data,element){
console.log(data[1].element);
}
我想國家,但結果是undefinded,如何解決這一問題?
感謝兄弟,它的真棒 –