Tag: 数组

从JSONArray中select所有包含的JSONObjects

我有一个JSONArray包含JSONObjects像这样{firstname:'John', lastname:'Doe'} 。 有没有办法直接select所有具有firstname == 'John' JSONObjects ,或者唯一的方法是循环数组,testing字段firstname并将所有匹配对象保存在另一个数组中? 谢谢

如何在MySQL和Node.js单列中存储数组值?

我可以在MySQL的单列中存储数组值吗? 因为我有一个数组,并希望存储在数据库中像这里是我想执行的一些东西。 var meida_array=[]; var media_length=response.media.length; for(var i=0;i<media_length;i++){ var parsed = url.parse(response.media[i]['link']); meida_array.push(parsed.host + parsed.path) } for (var i = 0; i < meida_array.length; i++) { console.log(meida_array[i]); } 我得到的数组,但卡在数据库中存储谢谢,提前:)

如何从JavaScript中的数组获得输出?

好,所以我一直在学习JavaScript,我知道最基本的东西,但我想知道如何从另一个数组中的文本基于数组的输出… 例如: var input = ["hi", "welcome"]; var output = ["hello", "thank you"]; 所以,如果我要input“嗨”,我希望返回是“欢迎”和“谢谢”相同的“你好”。 或input[0] = output[0]但我想searchinput数组,然后得到input的输出string。 可能是一个声明? 我一直试图find不同的方式,但是可能有人在那里可能知道如何做到这一点! 我很感激我得到的任何帮助! 编辑: 为了澄清,如果有人已经与IRC合作,我正在处理,所以我需要检查消息,并将它们与input数组或对象进行比较,然后将string输出到另一个数组或对象中的匹配键。

创build一个键值对(从mongoDB数据库中获取)的数组

我正在尝试以dynamic的方式创build一个key-value对的数组。 values部分是从我的routes数据库中获取的。 这就是我正在做的。 router.get('/account',isAuthenticated, function(req,res){ var following_users_details = []; for (var i = 0;i<req.user.following_users.length;i++) { var following_user = req.user.following_users[i];// following_users is a field of Array type in my MongoDB database User.findOne({'username' : following_user }, function(err,user) { following_users_details.push({ username: user.username, profilepic : user.photo, userbio : user.bio }); }); } res.render('users/userAccount',{user:req.user, following_users_details:following_users_details }); }); 但是当我尝试打印我的key-value对的数组时,我什么也得不到。 for(var i […]

Mongoose查询,查找B.array中具有A.array匹配项的typesB的所有项目

我有一个模特Person schemas.person = new mongoose.Schema({ firstname: {type: String}, lastname: {type: String}, age: Number, email: {type: String}, gender: {type: String}, matches: [{type: mongoose.Schema.Types.ObjectId, ref: models.Person}], }); matches是指另一个有相似兴趣的人(即约会目的) 假设我有10个male和10个female 。 我想写一个查询,给我一个与所有10个女性相互匹配的男性 – 也就是说,所有10个女性出现在他的matchesarrays中,他出现在所有10个女性的matchesarrays中。 所以在伪代码中,它看起来像这样: models.Person.find({"gender": "male"}).exec(function(err, men){ models.Person.find({"gender": "female"}).exec(function(err, women){ models.Person.find(some item from men.matches $in all women.matches}, function(err, result){ console.log(result); } } }); 最后一部分some item from men.matches […]

用socket.io命名数组

所以我正在创build一个多人游戏,我使用io.emit命令定期向客户端发送数据数组的更新。 setInterval(function(){ io.emit("sendBlocks", blocksClient); io.emit("sendMoreBlocks",test); }, 100); blocksClient是一个正常的数组。 而testing是一个命名的数组。 blocksClient = [{ posX: 0, posY: 0, solid: false }, { posX: 1, posY: 0, solid: false }, { posX: 2, posY: 0, solid: false },] test = [ block1: { posX: 1, posY: 5 }, block2: { posX: 35, posY: 42 } ] 到达客户端时,blocksClientvariables将完全正常工作。 而testingvariables在到达时将是完全空的。 […]

根据stringtesting子string的数组

我有一个bot名称的数组。 当一个用户或机器人访问我的网站,我得到的user-agent并希望testing是否存在其中的一个值在我的数组中。 var bots = [ "twitterbot", "linkedinbot", "facebookexternalhit", "pinterest", "dotbot", "rogerbot", "googlebot", "baiduspider", "yahoo! slurp", "bot", "spider", "simplepie", "yahooseeker", "embedly", "quora link preview", "outbrain", "vkshare", "monit", "pingability", "monitoring", "winhttprequest", "apache-httpclient", "getprismatic.com", "python-requests", "twurly", "yandex", "browserproxy", "webmeup-crawler", "qwantify" ]; var isBot = function(agent){ return bots.some(function(bot){ return bot.test(agent); }); } app.use(function(req, res, next){ var test = […]

Javascriptfilter很慢

我的节点应用程序中有两个大型数组。 var styles = [{itemID:…, styleID:…, styleNum:…, otherFields…}]; // 42455 items var products = [{productID:…, styleNum:…, otherFields…}]; // 72K items 我需要遍历产品,并从styles数组中获取关联的styleID,并将新项添加到新数组中。 样式数组按styleNumsorting。 这是我所尝试的: var i=0, len = products.length, items = new Array(products.length); for (i = 0; i < len; i++) { var workingItem = products[i]; var styleID = filterStyles(workingItem.styleNum)[0].styleID; var item = {styleID:…, other fields}; […]

JavaScript中对象的Array.prototype.map()等价于什么

我正在尝试从原始对象中取出一些对象到数组variables中。 console.log("news len", news["articles"].length); // this comes out to 9 for(var a in news["articles"]) { var results = []; results.push({ title:news["articles"][a]["title"], subtitle: news["articles"][a]["description"], item_url:news["articles"][a]["title"], image_url:news["articles"][a]["urlToImage"], }); } console.log("results len",results.length); //only contains one entry 有没有另一种方法来实现这一点,如果不是我做错了什么? 使用Node js,如果有帮助的话。

Lodash将对象添加到已经sorting的Obejct数组中

我正在寻找添加一个对象到已经sorting的对象数组中。 这样新的数组在添加新的对象之后应该被sorting。 这里是我基于对象属性displayName的sorting数组 [ { "id": "06BCCC25", "displayName":"Application" }, { "id": "39F886D9", "displayName":"Communication" }, { "id": "22EA4ED5", "displayName":"Device" }, { "id": "2F6E5FEA", "displayName":"Service" }, { "id": "317BF72C", "displayName":"Service02" } ] 现在我想补充 { "id": "07BSSC25", "displayName":"Mail" } 所以添加后它将被放置在第3和第4个索引之间。