Tag: 数组

数组长度属性JS的未注册成员

我遇到了这个代码,用于保持数组中的正向和反向引用: var arr = []; arr[arr['A'] = 0] = 'A'; arr[arr['B'] = 1] = 'B'; // On node interpreter arr // [ 'A', 'B', A: 0, B: 1 ] arr["A"] // 0 arr["B"] // 1 arr[0] // 'A' arr[1] // 'B' arr[2] // 'undefined' arr.length // 2 A: 0, B: 1成员被推到数组的末尾。 什么是这些成员,以及在这个过程中发生了什么, .length属性logging2而不是4?

SQL右键连接到JSON /数组

我试图将来自MySql right join的行数组转换成nodeJS上的array/json格式。 考虑到通用的mysql表: emp_id name 1 john 2 bill 3 anna fk_emp_id project 1 p1 1 p2 1 p3 2 p1 2 p4 而他们正确的join: id name fk_emp_id project 1 john 1 p1 1 john 1 p2 1 john 1 p3 2 bill 2 p1 2 bill 2 p4 3 anna 3 null 这是: rows […]

我无法停止asynchronous

所以我试图得到一个循环的数组,nodejs的asynchronous性质正在杀死我。 这是我的代码: getDevices(userIDs, function(result) { if (result) { sendNotification(messageUser, messageText, result); res.send("Success"); } else { res.send("ERROR"); } }); }); function getDevices(userIDs, callback) { var userDevices = []; var device = []; for (var i = 0; i < userIDs.length; i++) { searchRegisterDevices(userIDs[i], function(result) { if (result) { for (var j = 0; j < result.length; […]

用固定键将单个对象的值排列成对象数组

我有一个对象 { key1:'val1', key2:'val2', key3:'val3', key4:'val4' } 我需要将其转换为以下内容: [ {key:'val1'}, {key:'val2'}, {key:'val3'}, {key:'val4'} ] 最终对象的key是固定的。 我如何使用lodash或下划线来做到这一点? 我知道我可以使用_.values ,然后forEach ,但不知何故,感觉不对。

Twilio sendMessage不发送到数组中的所有值

我有问题与Twilio不发送消息到数组中的所有值。 var index; var a = req.body.numbers; console.log(a); if (req.body.numbers.indexOf("undefined") > -1) { console.log("No numbers stored"); } else { for (index = 0; index < a.length; ++index) { console.log(a[index]); client.sendMessage({ to: a[index], // Any number Twilio can deliver to from: '+19179246693 ', // A number you bought from Twilio and can use for outbound communication […]

如何从MongoDB中的另一个数组中search一个数组?

我有一个users表具有以下数据结构: [{ userID: 0, username: 'test0', petsForSale: [ { type: 'fish' }, { type: 'cats' } ], seekingPets: [ { type: 'dogs' }, { type: 'birds' } ] }, { userID: 1, username: 'test1', petsForSale: [ { type: 'guinea pigs' }, { type: 'dogs' }, { type: 'hamsters' } ], seekingPets: [ { type: 'ferrets' […]

如何设置数组jschema对象的默认值?

我试图设置默认值的数组在jschema与招摇。 下面是示例模式。 'Myobj': { 'type': 'object', 'title': 'Myobj', 'description': 'Some text', 'properties': { 'outputForms': { 'type': 'array', 'description': 'Some text', 'default': 'two', 'items': { 'type': 'string', 'enum': ['one','two'], }, 'maxItems': 4, 'uniqueItems': true, 'additionalItems': false } } } 这不行,我做错了什么? 我会很感激任何帮助。

在JavaScript中将无效的JSON对象转换为有效的JSON对象

我知道这是已经被问到的问题,但我没有得到任何问题的答案以前问… 我的问题是 – 服务器发送一个JSON对象的数组作为string,我想将string转换为有效的JSON数组。 示例:服务器发送像这样 '{ "ts": "3170075", "eventid": 25, "oper_minutes": 48577, "time": "2016-12-02T06:36:36Z", "lto": "7200000", "package_name": "XXX", "timestamp": "1480660593188", "action_type": "1", "events": [{ "device_name": 0, "key_category": 1, "eventid": 15, "ts": "2111" }, { "power_state": 3, "reason": 1, "eventid": 1, "ts": "2113" }] }, { "ts": "3170084", "eventid": 25, "oper_minutes": 48577, "time": "2016-12-02T06:36:36Z", "lto": "7200000", […]

parsing数组数组并使用nodemailer发送数据?

我想要使​​用NodeMailer在表中发送一组数据,如下所示: var results = [ { asin: 'B01571L1Z4', url: 'domain.com', favourite: false, createdAt: 2016-11-18T19:08:41.662Z, updatedAt: 2016-11-18T19:08:41.662Z, id: '582f51b94581a7f21a884f40' }, { asin: 'B01IM0K0R2', url: 'domain2.com', favourite: false, createdAt: 2016-11-16T17:56:21.696Z, updatedAt: 2016-11-16T17:56:21.696Z, id: 'B01IM0K0R2' }] 我正在试图做的,我在我的HTML中创build一个循环,然后通过数据循环。 我确实尝试了下面的内容,但似乎有什么限制我可以做的。 var sendUpdatedMerch = transporter.templateSender({ from: '"Test" <domain1@gmail.com>', // sender address subject: 'Test Updates', // Subject line html: '<div><table><thead><tr><th>ASIN</th><th>Url</th><th>Favourite</th><th>createdAt</th></tr></thead><tbody>{{result.forEach((item) => {<tr><td>{{asin}}</a></td><td>{{url}</td><td>{{favourite}}</td><td>{{createdAt}}</td></tr>})}}</tbody></table></div>' […]

节点arrays范围问题

我觉得这是一个非常愚蠢的问题,但我很难理解为什么我在callback函数中看到奇怪的行为。 我定义了一个名为clientList的数组,我导出并在其他文件中使用。 这里的代码在客户端连接到我的服务器时运行。 当我说clientList.splice或clientList.push,一切都按预期工作,而clinetList数组反映了我在其他需要()它的文件中的变化。但是,如果我说直接分配ClientList(例如clientList = []),那么更改不会反映在其他文件中。 如果我在callback中打印ClientList的内容,则这种改变将以任何方式反映出来。 var clientList = []; module.exports.socketHandler = (socket) => { var client = new Client(socket); clientList.push(client); socket.on('end',function(){ clientList = [] //This does not change the exported array clientList.splice(0,1); //This does change the exported array console.log("Client connection ended: "+clientList.length); //This always changes }); } module.exports.clientList = clientList; //IN A DIFFERENT […]