javascript - 如何读取同一行中的下一个值?
问题描述
我想读取变量“x1”中的值“-2.5”,以及另一个名为“y1”的变量中的值“0.4”。下面的行也是如此:在变量“x2”中读取“12.1”并在变量“y2”中读取“7.3”
var lines = [
"-2.5 0.4",
"12.1 7.3"
];
var x1 = parseFloat(lines[0]);
var y1 = jQuery(x1).next();
var x2 = parseFloat(lines[1]);
var y2 = jQuery(x2).next();
console.log(x1);
console.log(y1);
console.log(x2);
console.log(y2);
这是我正在解决的问题 和到目前为止我制作的代码,但不接受“错误答案 85%”
未捕获的 ReferenceError:未定义 jQuery
解决方案
我认为您可以查看此解决方案以供参考,希望对您有所帮助
var lines = [
"-2.5 0.4",
"12.1 7.3"
];
// This will convert a string into an array seperated by space (" ")
const generatePosition = string => string.split(" ");
// This will map all our initial values and change them into a full array
const pos = lines.map(string => generatePosition(string));
console.log(pos);
// From now you can freely access the variable the way you want, this is just for sample demo
const a = pos[0][0];
const b = pos[0][1];
console.log(a);
console.log(b);
推荐阅读
- laravel - 如何更正 Laravel 中的 public_path()?
- php - 如何从脚本 PHP 实现搜索
- javascript - composer.render() 无法正确渲染
- system.io.directory - 系统 io 目录未找到异常
- javascript - 从 iframe 中检测元素
- dart - TimeoutException:未来未完成
- python - 在 pandas 中查找重复项并创建集合
- php - 在 PHP 上进行抓取时出现错误的名称格式
- excel - VBA Issue Excel
- azure - Preventing 'Change Tier' for Blobs in Azure