我正在尝试执行内联拆分()然后拼接(),但它不起作用。
var newValue = "61471acddbbfef00961374b5ae961943,fafd1e39db3fa20084cc74b5ae961914";
var test = (newValue.toString().split(',')).splice(0,1,'test');
console.log(test);输出是:"61471acddbbfef00961374b5ae961943"阵列
但我期待着:"61471acddbbfef00961374b5ae961943",阵列“测试”
现在,如果我这么做
var test = newValue.toString().split(',');
test.splice(0,1,'test');
console.log(test);我得到了我想要的东西:"61471acddbbfef00961374b5ae961943",阵列“测试”
为什么我不能将其全部内联?:(newValue.toString().split(',‘,')).splice(0,1,'test');
发布于 2022-07-21 14:32:51
如果您绝对需要它作为一个单线杆,您可以使用concat和slice。
var str = "a,b,c";
var test = ['test'].concat(str.split(',').slice(0, 1));
console.log(test);
// output: [ "test", "a" ]
https://stackoverflow.com/questions/73067448
复制相似问题