Javascript删除数组中某个位置后的项

Javascript删除数组中某个位置后的项,javascript,html,arrays,loops,iterator,Javascript,Html,Arrays,Loops,Iterator,假设你永远不知道什么字符串将被传递到浏览器,任何长度的任何字符的任何组合,我想把这限制在让我们说。。50查尔 这就是我目前的情况: <script type="text/javascript"> var x = "Hello this sentance was created in the browser!" for(i=0; i<x.length; i++){ if(i == 50){ } } </script&

假设你永远不知道什么字符串将被传递到浏览器,任何长度的任何字符的任何组合,我想把这限制在让我们说。。50查尔

这就是我目前的情况:

<script type="text/javascript">
    var x = "Hello this sentance was created in the browser!"
    for(i=0; i<x.length; i++){
        if(i == 50){

        }
    }
</script>
我将如何删除位置50后数组字符串中的所有内容,我是否需要一个新的for循环,类似于这样,仅考虑伪代码可能是错误的:

loop remainder string{
    do until end of array{
        remove item
    }
}
还是有更好的方法?谢谢。

使用string.substringindexA[,indexB]方法:

返回一个索引和另一个索引之间的字符串子集,或通过 绳子的末端

使用string.substringindexA[,indexB]方法:

返回一个索引和另一个索引之间的字符串子集,或通过 绳子的末端

否:

否:

只要使用substr。这将返回符合条件的子字符串,例如,从开头开始,最多包含50个字符:

var x = "Hello this sentance was created in the browser!"

var shortString = x.substr( 0, 50 );
只要使用substr。这将返回符合条件的子字符串,例如,从开头开始,最多包含50个字符:

var x = "Hello this sentance was created in the browser!"

var shortString = x.substr( 0, 50 );

子字符串已经做了这个检查,所以不需要自己检查。不必要的函数调用的开销;Dsubstring已经做了这个检查,所以不需要自己检查。不必要的函数调用的开销;D
var x = "Hello this sentance was created in the browser!"

var shortString = x.substr( 0, 50 );