i have this array obj:
我有这个数组obj:
var scenari =[
{pos:'i4y',azione:('persa','avanti','indietro'),'peso':(0.3,0.4,0.3)},
{pos:'g4r',azione:('persa','avanti','indietro'),'peso':(0.3,0.4,0.3)}
];
How to retrieve the array in key azione? i try this but is print only 'indietro' and not array
如何在密钥azione中检索数组?我尝试这个但是只打印'indietro'而不是数组
console.log (scenari[0]['azione']);//indietro
3 个解决方案
#1
1
Parentheses not define an array and must be use brackets ([]
):
括号不定义数组,必须使用括号([]):
var scenari =[
{pos:'i4y',azione:['persa','avanti','indietro'],'peso':[0.3,0.4,0.3]},
{pos:'g4r',azione:['persa','avanti','indietro'],'peso':[0.3,0.4,0.3]}
];
console.log (scenari[0]['azione']);//indietro
#2
1
You are using () instead of [].
您正在使用()而不是[]。
If you use () last value will be the value of key
如果你使用()最后一个值将是key的值
var scenari =[
{pos:'i4y',azione:['persa','avanti','indietro'],'peso':(0.3,0.4,0.3)},
{pos:'g4r',azione:['persa','avanti','indietro'],'peso':(0.3,0.4,0.3)}
];
console.log (scenari[0]['azione']);
//If you use ()
//Example:
var ke = ('d','e');
console.log(ke);
#3
0
You are getting this issue because tuple javascript is treating the data in () as a expression, so to get the result in the way you want you have to use [] or convert your data in string .
您遇到此问题是因为元组javascript将()中的数据视为表达式,因此要以您希望的方式获得结果,您必须使用[]或将数据转换为字符串。
#1
1
Parentheses not define an array and must be use brackets ([]
):
括号不定义数组,必须使用括号([]):
var scenari =[
{pos:'i4y',azione:['persa','avanti','indietro'],'peso':[0.3,0.4,0.3]},
{pos:'g4r',azione:['persa','avanti','indietro'],'peso':[0.3,0.4,0.3]}
];
console.log (scenari[0]['azione']);//indietro
#2
1
You are using () instead of [].
您正在使用()而不是[]。
If you use () last value will be the value of key
如果你使用()最后一个值将是key的值
var scenari =[
{pos:'i4y',azione:['persa','avanti','indietro'],'peso':(0.3,0.4,0.3)},
{pos:'g4r',azione:['persa','avanti','indietro'],'peso':(0.3,0.4,0.3)}
];
console.log (scenari[0]['azione']);
//If you use ()
//Example:
var ke = ('d','e');
console.log(ke);
#3
0
You are getting this issue because tuple javascript is treating the data in () as a expression, so to get the result in the way you want you have to use [] or convert your data in string .
您遇到此问题是因为元组javascript将()中的数据视为表达式,因此要以您希望的方式获得结果,您必须使用[]或将数据转换为字符串。