[英]Does javascript not have bracket notation slicing? I.e. string[0:4]
I have been trying to find an answer to this, searched 'bracket notation string' but could not find anything.我一直试图找到答案,搜索“括号符号字符串”但找不到任何东西。 Say I have:
说我有:
let s = 'apple'
I know I can access any letter with s[x]
but can you slice a string this way using javascript.我知道我可以使用
s[x]
访问任何字母,但是您可以使用 javascript 以这种方式对字符串进行切片。 Ie IE
s[0:3]
to return "appl"
?返回
"appl"
?
Use Array.prototype.slice()
to obtain slices from an array:使用
Array.prototype.slice()
从数组中获取切片:
let s = 'apple'
let mySlice = s.slice(0,4)
console.log(mySlice) // appl
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.