上期(windows右键菜单设置位置)可以这样实现:
1. 常规 if - else if (x<50) { location.left = x; } else { location.right = x; } 2. 三目运算符 location[ x<50 ? 'left' : 'right' ] = x; 3. 布尔值加法 location[ ['right', 'left' ] [+(x<50)] ] = x;
本期题目
遍历对象数组,找出 ID = 1 的 子对象。
数组如下:
var testData = [
{id: 1,port: 'Tomhua(亚历山大港)', time:'2016-10', infact:1531, inrange:9156, export:28989, totalImport:13621},
{id: 1,port: 'Tomhua(亚历山大港)', time:'2016-11', infact:4153, inrange:34615, export:89894, totalImport:45234},
{id: 2,port: 'Namibe(木萨米迪亚)', time:'2016-10', infact:35612, inrange:6515, export:26648, totalImport:45132},
{id: 2,port: 'Namibe(木萨米迪亚)', time:'2016-11', infact:1561, inrange:8651, export:66484, totalImport:13241},
{id: 3,port: 'Bentiaba(本蒂亚巴)', time:'2016-10', infact:8413, inrange:24841, export:65311, totalImport:34545},
{id: 3,port: 'Bentiaba(本蒂亚巴)', time:'2016-11', infact:41484, inrange:1148, export:53114, totalImport:46486},
{id: 4,port: 'Lucira(卢西拉)', time:'2016-10', infact:6648, inrange:2664, export:84135, totalImport:37645},
{id: 4,port: 'Lucira(卢西拉)', time:'2016-11', infact:5266, inrange:4526, export:41351, totalImport:45915}
]