有没有办法访问拆分值而不将它们放入单独的值中?
var content = "some|content|of";
var temp = content.split("|");
var iwilluseit = "something" + temp[1] + temp[2]
Run Code Online (Sandbox Code Playgroud)
如何在没有临时变量的情况下执行此操作?(内联在iwilluseit var设置中)
这是非常低效的,但你可以多次调用 split :
var iwilluseit = 'something' + content.split('|')[1] + content.split('|')[2];
Run Code Online (Sandbox Code Playgroud)
还有 slice() + join() 选项:
var iwilluseit = 'something' + content.split('|').slice(1,2).join('');
Run Code Online (Sandbox Code Playgroud)
不过,实际上,仅创建临时变量是最好的方法。