javascript - 如何访问字符串对象的属性?

标签 javascript feathersjs

我有一个对象,需要在 before 钩子(Hook)中将其从字符串转换为 float :

{ '$near': 
   { '$geometry': { type: 'Point', coordinates: [Array] },
     '$minDistance': '0',
     '$maxDistance': '10000'
   }
}

如果 $near 属性是字符串,我如何访问它?我需要将“坐标”内的值从字符串转换为 float 。

console.log(location['$near']);

不起作用

最佳答案

这应该有效:

let thelocation = { '$near': 
   { '$geometry': { type: 'Point', coordinates:  [ "144.982", "-37.864" ] },
     '$minDistance': '0',
     '$maxDistance': '10000'
   }
};
let coords = [parseFloat(thelocation.$near.$geometry.coordinates[0]),
              parseFloat(thelocation.$near.$geometry.coordinates[1])];
console.log(coords);

输出:

Array [ 144.982, -37.864 ]

关于javascript - 如何访问字符串对象的属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50500162/

相关文章:

javascript - DFP 中的多个广告/广告素材尺寸

node.js - 羽毛 js 中的关联查询

node.js - 使用feathersjs rethinkdb适配器通过非sql选择不同的

javascript - 羽毛- Mongoose : Get by custom attribute in feathers-mongoose

analytics - Javascript 中的停用词删除

Javascript - 检查亚马逊对象以查看是否已定义

javascript - 在手动触发时绑定(bind)丢失的实例

javascript - 表达req.body为空。这是最好的方法吗?

express - 如何将我的 Feathers/Express 应用程序部署到 Nginx/Ubuntu?

FeathersJS 查询使用两个 $or but and'ed 在一起