+ 1
Someone explain this please
Hello. Please can someone look at this code and explain to me what substring(0,2) means. Also I saw splice(0,2) does same thing. Please explain what substring and splice does. https://code.sololearn.com/WP9otHuIt2m9/?ref=app
8 Respuestas
+ 2
These explain better than me
https://www.w3schools.com/jsref/jsref_substring.asp
https://www.w3schools.com/jsref/jsref_slice_string.asp
+ 2
splice or slice?
splice add or remove array items and the syntax is..
array.splice(positionOfArrayToStartAdding/Removing, howManyItems, itemToAdd1, ...)
slice and substring are basically the same.
but slice starts from the end of a string
+ 1
KrOW Thanks a lot.
But is there now any major difference between the two? Or they actually do dame thing?
+ 1
Hi,
Substring gets a part of an string.
string.substring(fromPosition, toPosition)
*toPosition: up to, but not including*
string index starts at position 0, so
substring(0, 2) extracts the two first characters of the string
+ 1
Hi Guillem Padilla What's the difference between it and splice
0
A difference its that slice accept negative numbers, substring dont
0
Guillem Padilla Sorry to bother. But pls an example would be nice. Can you write a code implementing splice? Thanks
0
If you see on links that i have posted, you will find examples also