我需要键country_code和language_code的值。
我试过了
sourceLanguageArray[0].$.country_code;
sourceLanguageArray[0].$.language_code;
我收到错误:
console.log(sourceLanguageArray[0].$.country_code);
^
ReferenceError: sourceLanguageArray is not defined
这就是数据结构的代码和控制台日志的样子:
source_language (includes country_code and language_code)
const sourceLanguageArray = _.map(ontomlClass, 'source_language');
console.log(sourceLanguageArray);
// => [ [ { '$': [Object] } ], [ { '$': [Object] } ],[ { '$': [Object] } ] ]
// => [ { '$': [Object] } ]
console.log(sourceLanguageArray[0]);
// => [ { '$': { country_code: 'US', language_code: 'en' } } ]
答案 0 :(得分:1)
var sourceLanguageArray = [[ { '$': { country_code: 'US', language_code: 'en' } } ]];
console.log("sourceLanguageArray[0]:", sourceLanguageArray[0]);
console.log("country code:", sourceLanguageArray[0][0].$.country_code);
console.log("language code:", sourceLanguageArray[0][0].$.language_code);
答案 1 :(得分:0)
试试这个:
sourceLanguageArray.forEach(function(item){
console.log(item[0]['$'][country_code]);
console.log(item[0]['$'][language_code]);
})