Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/369.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何拆分Word Javascript_Javascript - Fatal编程技术网

如何拆分Word Javascript

如何拆分Word Javascript,javascript,Javascript,那么,如何将一个词拆分为dumb和ways呢 我已经试过了 var word = 'dumbways' word.split() 但它不起作用,它只是“愚蠢的” 谢谢split方法搜索您在参数中指定的字符串,然后使用它来拆分周围的原始字符串 你的案子有点奇怪。首先,您需要以各种方式搜索单词,然后希望在找到该单词的位置断开字符串 我会以不同的方式编写代码: var word= "dumbways"; var splitted = word.split('ways'); //this will o

那么,如何将一个词拆分为dumb和ways呢

我已经试过了

var word = 'dumbways'
word.split()
但它不起作用,它只是“愚蠢的”

谢谢

split方法搜索您在参数中指定的字符串,然后使用它来拆分周围的原始字符串

你的案子有点奇怪。首先,您需要以各种方式搜索单词,然后希望在找到该单词的位置断开字符串

我会以不同的方式编写代码:

var word= "dumbways";
var splitted = word.split('ways'); //this will output ["1234", "56789"]
var first = splitted[0];
var second = splitted[1];
console.log('First is: ' + first + ', and second is: ' + second);
您还应该指定在找不到字符串时函数的行为方式

请看这里:

split方法搜索您在参数中指定的字符串,然后使用它分割周围的原始字符串

你的案子有点奇怪。首先,您需要以各种方式搜索单词,然后希望在找到该单词的位置断开字符串

我会以不同的方式编写代码:

var word= "dumbways";
var splitted = word.split('ways'); //this will output ["1234", "56789"]
var first = splitted[0];
var second = splitted[1];
console.log('First is: ' + first + ', and second is: ' + second);
您还应该指定在找不到字符串时函数的行为方式

请看这里:

您可以使用搜索:

let word='dumbways' 让index=word.search'ways' 设firstPart=word.substring0,索引 设secondPart=word.substringindex console.log'firstPart:',firstPart',secondPart:',secondPart您可以使用搜索:

let word='dumbways' 让index=word.search'ways' 设firstPart=word.substring0,索引 设secondPart=word.substringindex
console.log'firstPart:',firstPart',secondPart:',secondPart如注释中所述,delimter将从结果数组中删除,您只需将字符串拆分两次,如下所示:

var字=哑铃; var first=word.split'dumb'[1]; var second=word.split'ways'[0]; console.logfirst;
console.logsecond 如注释中所述,delimter将从结果数组中删除,您可以将字符串拆分两次,如下所示:

var字=哑铃; var first=word.split'dumb'[1]; var second=word.split'ways'[0]; console.logfirst;
console.logsecond 你的方法行不通。也许可以试试这样的方法:

var word=哑铃 var split=word.match/[\s\s]{1,4}/g;
log`第一个字:${split[0]}。第二个字:${split[1]}`您的方法无法工作。也许可以试试这样的方法:

var word=哑铃 var split=word.match/[\s\s]{1,4}/g;
log`第一个字:${split[0]}。第二个单词:${split[1]}`用字符而不是单词拆分它`单词。拆分为“w”;那是因为当你拆分某个东西时,它会将其删除。如果我用逗号分割'56,73',它将输出'56'和'73'。@NajamUsSaqib因此它将记录'dumb'和'ays'如何记录'dumb'和'ways'用字符而不是单词分割`单词。拆分为“w”;那是因为当你拆分某个东西时,它会将其删除。如果我用逗号分割'56,73',它将输出'56'和'73'。@NajamUsSaqib因此它将记录'dumb'和'ays'如何记录'dumb'和'ways'过滤器的用途是什么?你可以移除它们。过滤器的作用是什么?您可以删除它们。