Tag: 数组

node.js请求POST数组“第一个参数必须是string或缓冲区”

我想从一个node.js进程(客户端)发送到另一个(服务器)的数组。 我的代码在“客户端”node.js: var express = require('express'); var app = express(); var config = require('./config'); var bodyParser = require('body-parser'); var methodOverride = require('method-override'); var request = require('request'); app.set('port', process.env.PORT || 3009); app.use(bodyParser.json()); // parse application/json app.use(bodyParser.json({ type: 'application/vnd.api+json' })); // parse application/vnd.api+json as json app.use(bodyParser.urlencoded({ extended: true })); // parse application/x-www-form-urlencoded app.use(methodOverride('X-HTTP-Method-Override')); // override with the […]

如何通过在Node中的另一个对象中的位置来获取对象的值

在一个脚本中,我有一个包含其他几个对象的对象,都具有相同的结构。 它看起来像这样: wordlist = {word1: {count:2}, word2: {count:5}, word3: {count:3}, word4: {count:2}} 我想生成一个数组,每个单词的计数,所以它看起来像[2,5,3,2]。 有什么办法可以在Node.js中做到这一点? 我会想象使用for循环每次迭代到下一个子对象,但我将如何通过它在主对象中的位置来select子对象? 在一个数组中,你可以键入arrayName [2]来获得该数组中的第三个条目,是一个类似的东西可能与一个对象?

从对象属性recursion地生成文件path

我正在使用node.js和作为一个副项目,我创build一个模块,读取一个.json文件,parsing它,然后创build基于object properties和object values目录结构。 对象属性(keys)将是它自己的path/文件和对象值将是该path的文件列表 我试图通过对象递减递减,但我不知道如何从每个对象的最内层对象中提取path 同样,对象将是由用户创build的dynamic的。 var path = 'c:/templates/<angular-app>'; var template = { //outline of 'angular-app' src:{ jade:['main.jade'], scripts:{ modules:{ render:['index.js'], winodws:['index.js'], header:['header.js' ,'controller.js'], SCSS:['index.scss' ,'setup.scss'], } } }, compiled:['angular.js','angular-material.js' ,'fallback.js'], built:{ frontEnd:[],//if the array is empty then create the path anyways backEnd:[], assets:{ fontAwesome:['font-awesome.css'], img:[], svg:[] } } } //desired result… let out […]

从node.js Buffer中删除元素

我有一个这样声明的node.js缓冲区; var buffer_bin; buffer_bin = new Buffer("ABCDEF", "hex"); buffer_bin内容是二进制字节中的“ab cd ef”。 我想从buffer_bin删除第一个字节ab ,以使buffer_bin的内容变成“cd ef”。

Javascript:查找匹配多个字段的对象数组值

给定这个对象数组: [ { source_q_id: 'Q2B', target_q_id: null }, { source_q_id: 'Q2B', target_q_id: null }, { source_q_id: 'Q2B', target_q_id: null }, { source_q_id: 'Q5C', target_q_id: 'Q7' }, { source_q_id: 'Q5C', target_q_id: 'Q7' }, { source_q_id: 'Q5C', target_q_id: 'Q7' }, { source_q_id: 'Q5D', target_q_id: 'Q7' }, { source_q_id: 'Q5D', target_q_id: 'Q7' }, { source_q_id: 'Q5D', target_q_id: 'Q7' […]

错误:对象不是用于将数组返回给我的callback函数的函数

我正在从智能行读取表格值。我通过单击每一行读取每个值来读取表格。 exports.getTableData = function(callback){ var uiArray =[]; var count; aLib.loadCheck(client); //Clicks the first record of the table aLib.controlClick(client, obj.table.firstRecord); aLib.loadCheck(client); // Gets the text of the total number of records on the top left of the table and uses it to drive the loop client.getText(obj.topContent.recordCount, function (err, rowNum){ console.log(rowNum); count = rowNum.match(/\d/g).join(""); console.log('No. of records […]

从数组中find国家坐标

我正在写一个小应用程序。 我有以下数据 { "feat": [ { "type": "Feature", "id": "AFG", "properties": { "name": "Afghanistan" }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 61.210817, 35.650072 ], [ 64.546479, 36.312073 ], [ 64.746105, 37.111818 ], [ 65.588948, 37.305217 ], [ 65.745631, 37.661164 ], [ 66.217385, 37.39379 ], [ 66.518607, 37.362784 ], [ 67.075782, 37.356144 ], [ […]

将string数组减至最小的正则expression式值

我正在研究一个节点模块,它将file upload到s3,并在上传文件后执行了云端无效,但是考虑到失效不是免费的,我想将失效文件path上传到最小的正则expression式值,例如 [ 'library-latest-v2.min.js', 'library-latest-v2.min.js.map', 'library-latest-v2.test.min.js', 'library-latest-v2.test.min.js.map' ] 会变成library-latest-v2* 任何想法如何去写一个函数来做到这一点? 没有太多的运气谷歌search。 奖金点,如果它可以处理多种变化,例如 [ 'library-latest-v2.min.js', 'library-latest-v2.min.js.map', 'other-library-v3.min.js', 'other-library-v3.min.js.map' ] 会减less到['library-latest-v2*', 'other-library-v3*']但不知道这将是多么可能

NodeJS数组同步?

var membersStatArray = []; membersArray.forEach(function(member) { db.doneTodo .find({ 'victor._id': member._id }) .then((arrayOfUserVictories) => { membersStatArray.push({ email: member.email, victories: arrayOfUserVictories.length }); }) }); console.log(membersStatArray); 不pipe什么分贝。 我知道NodeJS是asynchronous的,但是什么是添加到数组,然后打印数组? 现在发生的是, console.log(membersStatArray) –> [] 因为它需要空数组。 这是什么方式?

JavaScript代码不按照想要的顺序运行(Node.js,MongoDB)

我知道Node.js的非阻塞I / O和什么是asynchronous函数,但是我很难指出为什么这个代码像运行一样运行。 我连接到一个MongoDB集合,search重复,把第一个值重复自己的数组对象(dupIndex)。 当数组打印时( console.log(dupIndex); ),我看到2个值,但是当我稍后使用.length属性( console.log(dupIndex.length); )时为0。 我想用dupIndex中的数据继续操作集合(就像使用deleteMany方法), 但是如果它显示0,我不能,至less不会这样。 有人可以解释这一点,并帮助我呢? 谢谢! //connect us to a running MongoDB server const {MongoClient, ObjectID} = require('mongodb'); var dataBase = "TodoApp"; //connecting to a database //connects to the database /TodoApp, if no such db exists it auto creates it MongoClient.connect(`mongodb://localhost:27017/${dataBase}`, (err, db)=>{ if(err){ //return or 'else' – […]