是否可以在 javascript 中为数组中的每个字符串创建自动子字符串? 例如:
var test =
[
"banana",
"apple",
"pear",
"cologne"
];
var conclusion = prompt("choose one")
// something that would get the following result:
if( conclusion === banana)
{
print("b");
print("ba");
print ("ban");
// ...
print("banana");
// and the same for the rest of the strings in the Array.
最佳答案
这是一个简短的解决方案,我让你自己理解作为作业:
var test ="banana";
test.split("").forEach((x,i,arr) => console.log(arr.slice(0,i+1).join("")));
关于javascript:为数组中的每个字符串创建自动子字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41088286/