
我是这样从网址获取id的。两者都是object。如果我像id[0]一样识别它,那么它就会给我数据类型String
但作为一个人类,我能理解一个是String,另一个是Integer。
如何使用JS Code识别?
发布于 2020-12-18 19:22:21
尝试解析为整数:
function roughScale(x, base) {
const parsed = parseInt(x, base);
if (isNaN(parsed)) { return 0; }
return parsed * 100;
}
console.log(roughScale(' 0xF', 16));
// expected output: 1500
console.log(roughScale('321', 2));
// expected output: 0https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt
https://stackoverflow.com/questions/65356130
复制相似问题