I'm trying to access data in the following array but am having trouble using .forEach
I want to access all singleLine.text
but it won't let me. I am guessing because there are multiple singleLines at the same level.
var a = [
{ boxedCharacters: { text: '1040043' } },
{ singleLine: { text: '東京都中央区日本橋新古町' } },
{ singleLine: { text: 'この度は、数多くのお店の中から当店を'} },
{ singleLine: { text: 'お選びご来店頂きまして誠にありがとう'} }
]
a.forEach(function(value){
console.log(value.singleLine.text)
})
I've tried this but it isn't the best solution since it'll create an empty array for boxedCharacters because it won't match the passed in property value. Also, I could have multiple boxedCharaters and other keys with the same name.
function genNewArray(jsonArray)
{return results.map(function(a){
return {[jsonArray]: a[jsonArray]}
})
}
var i = genArray(‘singleLine’)
Any better ideas of how I could access the values?