我有一个像
这样的数组的javascript对象ProductPart.objects.filter(part=v)
但var coordinates = {
"a": [
[1, 2],
[8, 9],
[3, 5],
[6, 1]
],
"b": [
[5, 8],
[2, 4],
[6, 8],
[1, 9]
]
};
返回undefined。
Fiddle is here
答案 0 :(得分:13)
那是因为coordinates
Object
不是Array
,请使用for..in
var coordinates = {
"a": [
[1, 2],
[8, 9],
[3, 5],
[6, 1]
],
"b": [
[5, 8],
[2, 4],
[6, 8],
[1, 9]
]
};
for (var i in coordinates) {
console.log(coordinates[i])
}
var coordinates = {
"a": [
[1, 2],
[8, 9],
[3, 5],
[6, 1]
],
"b": [
[5, 8],
[2, 4],
[6, 8],
[1, 9]
]
};
var keys = Object.keys(coordinates);
for (var i = 0, len = keys.length; i < len; i++) {
console.log(coordinates[keys[i]]);
}
答案 1 :(得分:8)
coordinates
是一个对象。默认情况下,javascript中的对象不具有length
属性。某些对象具有length属性:
"a string - length is the number of characters".length
['an array', 'length is the number of elements'].length
(function(a, b) { "a function - length is the number of parameters" }).length
您可能正在尝试查找对象中keys
的数量,这可以通过Object.keys()
完成:
var keyCount = Object.keys(coordinates).length;
请注意,因为length
属性可以添加到任何对象:
var confusingObject = { length: 100 };
答案 2 :(得分:2)
http://jsfiddle.net/3wzb7jen/2/
while( (fscanf(fp,"%d",&num)) != EOF) // This is the line 46