+ 1
How can i select multiple indexes of an array/string with JS?
Python has things like "[3:]","[1:5]" and "[::-1]". How can I get similar results in JS?
3 ответов
+ 3
I don't know Python, but I will list all the similar methods for JS.
var str = "SoloLearn" ;
str.substr(2, 3) // starting from the second index, selects 3, outputs "loL"
str.substring(2, 6) // starting from the second index, selects up to but not including the sixth index, outputs "loLe"
str.slice(2, 6) // the same as substring
str.slice(2) // selects from the second index to the last index, outputs "loLearn"
str.slice(2, -2) // selects from the second index, selects up to but not including the second last index, outputs "loLea"
var arr = ["Apple", "Pen, "Pineapple", "Pen"]
arr.splice(1, 2) // starting from the first index, selects 2, outpus "Pen, Pineapple"
+ 2
I'm glad to help
+ 1
PPAP 😁
But thx, you really really helped me!
I was trying to use For Loops, it clearly didn't work lol
Again, thx, you saved a life today